I
I
Ivan2016-07-10 09:21:42
In contact with
Ivan, 2016-07-10 09:21:42

How to copy access_token from address?

I use VKontakte authorization by sending the user to this address

oauth.vk.com/authorize?client_id=<?=$client_id;?>&display=page&redirect_uri=https://oauth.vk.com/blank.html&scope=<?=$scope;?>&response_type=token&v=5.37

After authorization, the contact will redirect to the following address:
oauth.vk.com/blank.html#access_token=0000000000&expires_in=0&user_id=111111

How can I get the access_token from here in the controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OM1, 2016-07-10
@Nickname-no

$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);

$token['access_token']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question