Answer the question
In order to leave comments, you need to log in
json parsing - cancel group invite?
Actually the goal: to cancel sent invitations to the VKontakte group.
Using the groups.getInvitedUsers method, I try to get a list of sent invitations, with offset = '5' to capture older invites, and count = '1' giving one result per request.
The server response to the groups.getInvitedUsers request should, in theory, be parsed and the request sent using the groups.removeUser method with the received user ID.
But since I'm a cancer, I suspect that I'm doing the parsing wrong.
Actually my redneck code:
<?
$token = 'e9ac7efaaf876f76728475fdf3061d43dd7f1091d47a6804b5';
$group_id = '112345678';
$offset = '5';
$count = '1';
$getlist = curl('https://api.vk.com/method/groups.getInvitedUsers?group_id='.$group_id.'&offset='.$offset.'&count='.$count.'&access_token='.$token);
$json2 = json_decode($getlist, true);
$resultid = $json2['items']['id'];
$deluser = curl('https://api.vk.com/method/groups.removeUser?group_id='.$group_id.'&user_id='.$resultid.'&access_token='.$token);
function curl($url) {
$ch = curl_init($url);
curl_setopt ($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt ($ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt ($ch,CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec($ch);
curl_close ($ch);
return $response;
}
?>
response: {
count: 535,
items: [{
id: 123456700,
first_name: 'Имя',
last_name: 'Фамилия'
}]
}
$json2 = json_decode($getlist, true);
$resultid = $json2['items']['id'];
Answer the question
In order to leave comments, you need to log in
$resultid = $json2['response']['items'][0]['id'];
Damn, isn't that obvious?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question