Answer the question
In order to leave comments, you need to log in
Registration on the site through VK?
I do registration through vk on php , when opening the link, this appears - {"access_token":"xxxxxxxxxxxxxxxxxxxxx","expires_in":x,"user_id":x,"email":"x"}(Of course, I removed the data). But when parsed, it throws an Error, here is the code:
<?
$client_id = 'xxxxxx'; // ID приложения
$client_secret = 'xxxxxxxxxxx'; // Защищённый ключ
$redirect_uri = 'xxxxxxxxxxxxxxx'; // куда ответ
if (isset($_GET['code'])) {
$result = false;
$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)or die('Error');
echo $token, 'https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params));
if (isset($token['access_token'])) {
$params = array(
'uids' => $token['user_id'],
'fields' => 'uid,first_name,last_name,screen_name,sex,bdate,photo_big',
'access_token' => $token['access_token'],
);
$userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
$email = $token['email']; // почта юзера
if (isset($userInfo['response'][0]['uid'])) {
$userInfo = $userInfo['response'][0];
$result = true;
}
}
if ($result) {
echo 1;
echo "Социальный ID пользователя: " . $userInfo['uid'];
echo "Имя пользователя: " . $userInfo['first_name'];
echo "Фамилия пользователя: " . $userInfo['last_name'];
echo "Emai пользователя: " .$email;
echo "Ссылка на профиль пользователя: " . $userInfo['screen_name'];
echo "Пол пользователя: " . $userInfo['sex'];
echo "День Рождения: " . $userInfo['bdate'];
echo "URL к фото: ".$userInfo['photo_big'];
}
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question