Answer the question
In order to leave comments, you need to log in
How to form a request using the execute method in VK api?
Please explain, I don't understand! I'm trying myself in VK api , my knowledge of php is superficial... I
'm uploading information using curl, example:
$GroupInfo['url'] = 'https://api.vk.com/method/groups.getById';
$GroupInfo['post'] .= 'group_id='.$group_id;
$GroupInfo['post'] .= '&fields=members_count';
$GroupInfo['post'] .= '&access_token='.mc_decrypt($_SESSION['UserInfo']['access_token'], ENCRYPTION_KEY);
$GroupInfo['post'] .= '&v='.$System['api']['version'];
$GroupInfo['ch'] = curl_init($GroupInfo['url']);
curl_setopt ($GroupInfo['ch'], CURLOPT_URL, $GroupInfo['url']);
curl_setopt ($GroupInfo['ch'], CURLOPT_HEADER, 0);
curl_setopt ($GroupInfo['ch'], CURLOPT_NOBODY, 0);
curl_setopt ($GroupInfo['ch'], CURLOPT_RETURNTRANSFER, true);
curl_setopt ($GroupInfo['ch'], CURLOPT_POST, true);
curl_setopt ($GroupInfo['ch'], CURLOPT_POSTFIELDS, $GroupInfo['post']);
curl_setopt ($GroupInfo['ch'], CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($GroupInfo['ch'], CURLOPT_SSL_VERIFYHOST, 0);
$GroupInfo['out']=curl_exec($GroupInfo['ch']);
curl_close($GroupInfo['ch']);
$GroupInfo['get'] = json_decode($GroupInfo['out'], true);
Answer the question
In order to leave comments, you need to log in
Found in the internet a clear example, almost figured it out!
the only moment - here I have formed queries:
$code .= 'var out = API.users.get({...});';
$code .= 'var out = out + API.groups.getById({...});';
$code .= 'var out = out + API.stats.get({...});';
$code .= 'return out;';
$execute = json_decode(GetVK('https://api.vk.com/method/execute', array(
'code' => $code,
'access_token' => mc_decrypt($_SESSION['UserInfo']['access_token'], ENCRYPTION_KEY),
'v' => $System['api']['version']
)), true);
$execute['response']
, it turns out that at the next level I have 3 arrays that correspond to my 3 requests in turn!? Correctly? function vk_query($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURLOPT_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$members_all = array();
for ($i=0; $i<$query_count; $i++){
$offset_out = $i*25000;
$query = "
var members = API.groups.getMembers({\"group_id\": $group_vk_id, \"count\":1000, \"fields\": \"sex, bdate\", \"offset\": $offset_out}).items;
var offset = 1000;
while (offset < 25000 && (offset+$offset_out < $group_vk_count)){
members = members + API.groups.getMembers({\"group_id\": $group_vk_id, \"count\":1000, \"fields\": \"sex, bdate\",\"offset\": ($offset_out + offset)}).items;
offset = offset + 1000;
};
return members;
";
$result = json_decode(vk_query('https://api.vk.com/method/execute', array(
'access_token' => $_SESSION['access_token'],
'code' => "$query",
'v' => '5.37'
)), true);
//echo '<pre>';
//print_r($result);
$members_all[] = $result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question