Hello I have a problem. I'm trying to get banned users from a group via VK API.
Here is my code:
/**
* Created by unixwz on 5/30/16.
*/
get_all_groups function(user_id, access_token)
{
ban_count = 0;
$.ajax({
type: "POST",
url: "engine/handler.php",
data: {"user_id": user_id,
"access_token": access_token,
"act" : "get_group"},
response: "text",
success: function (data) {
user_groups = JSON.parse(data) ['response'];
for(i = 1; i < user_groups.length; i++)
{
$("#all_group").append(
"<br><label><input value="" + user_groups[i]["gid"] + "" id="group" + i + "" type="checkbox">"
+ user_groups[i]["name"] + " - " + user_groups[i]["gid"] + "</label>",
null);
get_number_of_banned_users(user_groups[i]["gid"], access_token);
// get number of banned users for all groups
}
}
});
}
get_number_of_banned_users function(group_id, access_token)
{
$.ajax({
type: "POST",
url: "engine/handler.php",
data: {"group_id": group_id,
"access_token": access_token,
"act" : "get_banned_num"},
response: "text",
success: function (data) {
alert(data);
}
});
}
Here is the PHP handler:
function get_all_groups($user_id, $access_token)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.vk.com/method/groups.get?user_id=". $user_id ."&count=1000&filter=admin,editor,moder&extended=1&access_token=". $access_token ."");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
$response = curl_exec($curl);
return $response;
}
function get_number_of_banned_users($group_id, $access_token)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.vk.com/method/groups.getBanned?group_id=". $group_id ."&count=200&access_token=". $access_token ."");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
$response = curl_exec($curl);
return $response;
}
if(isset($_POST["act"]))
{
switch ($_POST["act"])
{
case "get_group":
if(isset($_POST["user_id"]) && isset($_POST["access_token"]))
{
get_all_groups echo($_POST["user_id"], $_POST["access_token"]);
}
break;
case "get_banned_num":
if(isset($_POST["group_id"]) && isset($_POST["access_token"]))
{
get_number_of_banned_users echo($_POST["group_id"], $_POST["access_token"]);
}
break;
}
}
It turns out that the first method groups.get works fine because it only requires a token without access rights, and the second method groups.getBanned always returns
{"error":{"error_code":15,"error_msg":"Access denied: no access to this call method","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"groups.getBanned"},{"key":"group_id","value":"119484487"},{"key":"count","value":"200"}]}} although I autorisoes correctly and the access rights the app expose, but all the same writes that there is no access. Application standalone.
<a href="https://oauth.vk.com/authorize?client_id=5485927&redirect_uri=http://localhost/&display=page&scope=groups&response_type=code">
<button type="button" class="btn btn-success">Login using OpenID</button>
</a>
Help solve the problem.