P
P
proton-m2015-11-19 21:29:00
JavaScript
proton-m, 2015-11-19 21:29:00

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

3 answer(s)
V
Vasily Letuev, 2015-11-20
@xo6a

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>');
}

what you will do next JavaScript is your business, the main thing is that the pictures are in html

P
proton-m, 2015-11-20
@proton-m

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);});
  });

maybe I'm doing something wrong? here is the whole code, I run in denver
<!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>

E
eventpromo, 2017-03-02
@eventpromo

How did you solve the issue?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question