I
I
Ivan Steblev2015-08-15 21:29:29
Angular
Ivan Steblev, 2015-08-15 21:29:29

How to get data using VK API in Angular?

I can not get data through the Vkontakte api. Here is the service:

app.factory('VkontakteCount', ['$http',
    function($http) {
        return {
            fetchVk: function(callback) {
                
                var methodName = 'groups.getMembers';
                var groupID = 76922753;                
                var url = 'https://api.vk.com/method/'+methodName+'?group_id='+groupID+'&callback=JSON_CALLBACK';

               $http.jsonp(url).success(function(response) {
                    callback(response.data);
                });                
            }
        }
    }
]);

Here is the controller piece:
VkontakteCount.fetchVk(function(data){
  	$scope.vkcount = data;  	
  });

There are no errors in the console, but no result either. Please help, has anyone come across this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Gromadchuk, 2015-08-16
@flexsa

$http.jsonp(url).success(function(response) {
    callback(response.data);
});

Let's take a look at this specifically. You say that there is nothing in the console, but why should there be something there? In order for something to be in the console, you need to request it with a line:
$http.jsonp(url).success(function(response) {
    console.log(response);
});

Further, we are faced with the fact that in the console you will see an object with a response from VKontakte. For correctness, let's rename the response variable from response to data. Then we assign the number of community members to your vkcount variable. As a result, you will get the result below, from which you will understand everything and you can change everything for yourself.
$http.jsonp(url).success(function(data) {
    $scope.vkcount = data.response.count;
});

S
shekspir, 2016-02-17
@shekspir

Maybe someone will help. :)
https://github.com/shekspir55/ngVk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question