L
L
Lu_den2014-11-10 13:21:34
PHP
Lu_den, 2014-11-10 13:21:34

How to get access_token Vkontakte (problem at the last step)?

I'm trying to get the access_token of the logged in user. The authorization link is formed correctly, a standard dialog appears, then it is redirected to a page with the following content:

$code = $_GET['code'];
$secret = 'dgfgdfgdfgew545'; //секретный ключ приложения
$idapp = '123456'; //id приложения

$url = 'https://oauth.vk.com/access_token?client_id='.$idapp.'&client_secret='.$secret.'&code='.$code.'&redirect_uri=http://site.com/vk.php'; 
echo $url;

$token = json_decode(file_get_contents($url), true); 
var_dump($token);

echo 'Добро пожаловать';

The address of the page for obtaining the token ($url) and NULL ($token) is displayed. Moreover, if you go to $url - the browser will display a normal json string with a token. Tell me what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Benkovsky, 2014-11-10
@benbor

https://vk.com/dev/auth_sites - you seem to be doing everything right.
Look at this line $token = json_decode(file_get_contents($url), true); see what file_get_contents returns

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question