Answer the question
In order to leave comments, you need to log in
How to take a photo from VK using vk api and JavaScript?
Hello! Help, I did not find information on how to get a json file with links to photos from VK (let's say from a group) using javascript (or angular). Maybe someone knows a link to the same question or I will be very grateful for a small and simple example :)
Answer the question
In order to leave comments, you need to log in
vk api is php. So?
<?php
$owner_id = id пользователя где размещена фото или id группы (если id группы, тогда это отрицательное число) например: -78208963
$album_id = id альбома
//делаем запрос к апи вк
$resp = file_get_contents('https://api.vk.com/method/photos.get?owner_id='.$owner_id.'&album_id='.$album_id.'&count=7&v=5.31');
//count - количество
//v - версия
//декодируем полученный json массив
$data = json_decode($resp, true);
//вывод фоток в ширину 604
foreach($data["response"]["items"] as $photo){
echo('<div class="img" style="background-image:url('.$photo["photo_604"].')"></div>');
}
Guys, I took this block of code, in theory it should work, but it does not) With the help of angular
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("https://api.vk.com/method/photos.get?owner_id=-41781142&album_id=161700051&count=2")
.success(function (response) {console.log(response);});
});
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("https://api.vk.com/method/photos.get?owner_id=-41781142&album_id=161700051&count=2")
.success(function (response) {console.log(response);});
});
</script>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question