Skip to content

Instantly share code, notes, and snippets.

@nergal
Created October 19, 2011 13:11
Show Gist options
  • Save nergal/1298239 to your computer and use it in GitHub Desktop.
Save nergal/1298239 to your computer and use it in GitHub Desktop.
Vkontakte API undocumented restricted access
<?php
function request($url, Array $params = array()) {
array_walk($params, function($item, $key) use ( & $url) {
$url = str_replace('{'.$key.'}', $item, $url);
});
$curl = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 300,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
);
curl_setopt_array($curl, $options);
$data = curl_exec($curl);
curl_close($curl);
$result = json_decode($data, TRUE);
return $result;
}
$config = array(
'application_id' => 1,
'application_secret' => '$eCr3t+K3y',
'group_id' => 123,
);
$token_url = 'https://api.vkontakte.ru/oauth/access_token?client_id={application_id}&client_secret={application_secret}&grant_type=client_credentials';
$count_url = 'https://api.vkontakte.ru/method/groups.getMembers?gid={group_id}&count=0&access_token={access_token}';
$token = request($token_url, $config);
$count = request($count_url, $config + $token);
if (isset($count['error'])) {
$error = $count['error'];
throw new Exception($error['error_msg'], $error['error_code']);
} elseif (isset($count['response'])) {
$response = $count['response'];
$count = $response['count'];
echo $count;
} else {
throw new Exception('Unexpected response');
}
@nergal
Copy link
Author

nergal commented Oct 19, 2011

Суть проблемы, что при корректных значениях application_id и application_secret нельзя вызвать метод groups.getMembers для публичной группы. В официальной документации об этом ни слова.

Метод возвращает следующую ошибку с кодом 5:
User authorization failed: method is unavailable with server auth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment