A
A
Alexander Andreev2019-10-21 18:17:34
In contact with
Alexander Andreev, 2019-10-21 18:17:34

How to save the access_token received from VK?

I use the PHP SDK library to work with the Vkontakte API. The documentation says:

After successful authorization, the browser will redirect the user to the specified redirect_uri. access_token will be sent as a fragment to the address you specified:
For user access key
https://example.com#access_token=533bacf01e11f55b5...

Authorization passes, the token is generated, but it is not clear how to get this data and save it for further work with the API. There is no data in any global array. How to get access_token from this VK response? API request examples use this $access_token :
$vk = new VKApiClient();
$response = $vk->users()->get($access_token, array(
    'user_ids' => array(1, 210700286),
    'fields' => array('city', 'photo'),
));

PS pay attention to the fact that instead of the sign ? after the url-address is # this link is given by vk after the application is granted permissions from the user.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lightmanLP, 2019-10-23
@lightmanLP

JavaScript document.location.hash
https://www.w3schools.com/jsref/prop_loc_hash.asp

I
I Phoenix I, 2020-07-30
@PhoenixX33i

So that instead of the # sign , the parameters are passed with the ? you need to use not the Implicit flow, but the Authorization code flow .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question