Не могу выполнить метод groups.get
. VK API
возвращает:
[error_code] => 5 [error_msg] => User authorization failed: no access_token passed
При этом другие методы (getCities
, getCountries
) работают.
Вот эта строка неверно работает:
$groups = json_decode(@file_get_contents('https://api.vk.com/method/groups.get?uid'.$token[user_id].''));
Может проблема в том, что при получении token [expires_in] => 0
?
Вот сам код:
<?
require_once('common_use.php');
session_start();
$client_id = '***';
$client_secret = '****';
$redirect_uri = 'http://site/outh.php';
$result = false;
if (isset($_GET['code'])) {
$params = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'code' => $_GET['code'],
'redirect_uri' => $redirect_uri
);
$token = json_decode(@file_get_contents('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true);
if (isset($token['access_token'])) {
$params = array(
'uids' => $token['user_id'],
'fields' => 'uid,city,country,first_name,last_name,screen_name,sex,bdate,photo_big,photo_rec,contacts',
'access_token' => $token['access_token']
);
$userInfo = json_decode(@file_get_contents('https://api.vk.com/method/users.get?' . urldecode(http_build_query($params))), true);
if (isset($userInfo['response'][0]['uid'])) {
$userInfo = $userInfo['response'][0];
$result = true;
// Вот тут ошибка
$groups = json_decode(@file_get_contents('https://api.vk.com/method/groups.get?uid'.$token[user_id].''));
$sig = md5("api_id=".$client_id."method=getCitiesv=2.0api_secret=".$client_secret."");
$res = json_decode(@file_get_contents('https://api.vk.com/method/getCities?api_id='.$client_id.'&sig='.$sig.'&v=2.0&cids='.$userInfo[city].''));
$city = $res -> response[0] -> name;
}
}
}
?>