M
M
makag2016-06-14 11:01:29
In contact with
makag, 2016-06-14 11:01:29

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;
}
?>

On the request groups.getInvitedUsers, VK returns data in the following format:
response: {
count: 535,
items: [{
id: 123456700,
first_name: 'Имя',
last_name: 'Фамилия'
}]
}

And, as I suspect, the plug goes through at the stage of parsing this answer, by the construction
$json2 = json_decode($getlist, true);
$resultid = $json2['items']['id'];

Tell me where to dig?
Thanks in advance for the helpful comments and replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-06-14
@makag

$resultid = $json2['response']['items'][0]['id'];
Damn, isn't that obvious?

B
bikuka, 2018-08-28
@bikuka

Here is a working javascript script:
Took from here - - www.bubasik.com/kak-v-vkontakte-cancel-vse-prigla...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question