Wrote this stored procedure:
var q = Args.q; var count = Args.count; var groups = API.groups.search({ "q": q, "count": count }); var result = []; if (groups.length == 0) { return []; } else { var i = 0; while (i < groups.items.length) { var members = API.groups.getMembers({ "group_id": groups.items[i].id, "count": 0 }).count; result = result + [{ "group": groups.items[i], "members": members }]; i = i + 1; } } return result; It returns a list of found groups along with the number of people in this group. In the web environment of VK it works fine.
I try to use it in my application:
https://api.vkontakte.ru/method/execute.getSourceInfo?access_token=' + self.accessToken + 'q=' + name + '&count=3' + '&callback=JSON_CALLBACK I get the error:
"User authorization failed: invalid access_token (4)."
And this is despite the fact that all the methods that are used in the procedure, when called directly from the application, work perfectly.
What kind of magic?
Update 10/13/2016
The line with the method call is now formed like this:
'https://api.vk.com/method/execute.getSourceInfo?access_token=' + self.accessToken + '&q=' + name + '&count=3' + '&version=5.57&callback=JSON_CALLBACK' But the stored procedure is still not executed. Errors:
error_code: 7 error_msg: "Permission to perform this action is denied" method: "groups.search" error_code: 7 error_msg: "Permission to perform this action is denied" method: "execute.getSourceInfo" I also suggested that you need to explicitly pass the token to the groups.search method, but this did not help either:
var q = Args.q; var count = Args.count; var access_token = Args.access_token; var groups = API.groups.search({ "q": q, "count": count, "access_token": access_token, }); ... In general, I do not understand what the problem is.
Updated on 10/14/2016
It was possible to get access to the execution of the stored procedure. On the advice of @terron, requested access to groups. Now the following problem has arisen - the response is empty when called on the client. When called in a VC environment, it works fine:
var q = Args.q; var count = Args.count; var groups = API.groups.search({ "q": q, "count": count }); var result = []; if (groups.length == 0) { return []; } else { // Все, что добавляется в results в этом цикле - не доступно при вызове. // При чем, если вызывать процедуру в окружении ВК - все работает. var i = 0; while (i < groups.items.length) { var members = API.groups.getMembers({ "group_id": groups.items[i].id, "count": 0 }).count; result = result + [{ "group": groups.items[i], "members": members }]; i = i + 1; } return result; } I call the procedure as follows (AngularJS):
var findContentSource = function(name) { var self = this; return $q(function(resolve, reject) { $http.jsonp( 'https://api.vk.com/method/execute.getSourceInfo?q=' + window.encodeURIComponent(name) + '&count=3&version=5.58&callback=JSON_CALLBACK&access_token=' + self.accessToken ).success(function(data) { console.log(data); }); }); }