Вот сам код:
<?php
$client_id = '4661884'; // ID приложения
$client_secret = 'XXXXXXXXXXXXXXX'; // Защищённый ключ
$redirect_uri = 'http://xddanik.esy.es/'; // Адрес сайта
$url = 'http://oauth.vk.com/authorize';
$params = array(
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'response_type' => 'code'
);
echo $link = '<p><a href="' . $url . '?' . urldecode(http_build_query($params)) . '">Авторизироватся через ВКонтакте</a></p>';
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);
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);
if (isset($userInfo['response'][0]['uid'])) {
$userInfo = $userInfo['response'][0];
$result = true;
}
}
if ($result) {
echo "Ваш id: " . $userInfo['uid'] . '<br />';
echo "Ваше имя: " . $userInfo['first_name'] . '<br />';
echo "Ваша фамилия: " . $userInfo['last_name'] . '<br />';
echo "Ваш домен: /" . $userInfo['screen_name'] . '<br />';
echo "Ваш пол: " . $userInfo['sex'] . '<br />';
echo "День Рождения: " . $userInfo['bdate'] . '<br />';
echo '<img src="' . $userInfo['photo_big'] . '" style="-webkit-border-radius:100px;-moz-border-radius:100px;border-radius:100px;" />'; echo "<br />";
}
}
?>
А вот ошибка:
Код:
|
Warning: file_get_contents() [function.file-get-contents]: Couldn't connect to server in /home/u897301726/public_html/index.php on line 144
Warning: file_get_contents(https://api.vk.com/method/users.get?uids=142099162&fields=uid,first_name,last_name,screen_name,sex,bdate,photo_big&access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX) [function.file-get-contents]: failed to open stream: operation failed in /home/u897301726/public_html/index.php on line 144 |
Я вставил эти XXX чтобы мой токен не узнали!
Помогите нубу!