Answer the question
In order to leave comments, you need to log in
What's wrong with the VK API?
Hello, I have such a problem. I'm trying to get banned users from a group using the VK API.
Here is my code:
/**
* Created by unixwz on 5/30/16.
*/
function get_all_groups(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
}
}
});
}
function get_number_of_banned_users(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);
}
});
}
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"]))
{
echo get_all_groups($_POST["user_id"], $_POST["access_token"]);
}
break;
case "get_banned_num":
if(isset($_POST["group_id"]) && isset($_POST["access_token"]))
{
echo get_number_of_banned_users($_POST["group_id"], $_POST["access_token"]);
}
break;
}
}
<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">Авторизоваться через ВКонтакте</button>
</a>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question