V
V
Viktor Koreysha2014-07-28 13:35:09
PHP
Viktor Koreysha, 2014-07-28 13:35:09

How to get Access token in vk API after server authorization?

I'm trying to figure out the VK API. According to the documentation I do server authorization. The contact redirects the user back to me and the GET parameter gives me the code.
As it turned out, that's not all, and I need to somehow get an access_token. To do this, I make a request:

$resp = file_get_contents('https://api.vk.com/oauth/token?client_id='.$api_id.'&code='.$code.'&client_secret='.$secret_key.'&redirect_uri='.$uri);
var_dump($resp);

Substitute, of course
$api_id - the given application id
$code - Sent $_GET['code']
$secret_key - the given application key $
uri - the same url to which the code came
I get bool(false)
then I see the following error:
{"error":"invalid_grant","error_description":"Code is invalid or expired."}
What am I doing wrong? I ask you not to kick with your feet - I really did not find answers and descriptions by mistake.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Viktor Koreysha, 2014-07-28
@Iktash

Thanks to all. I tried from another user - the first time everything worked, the second the same error. Apparently, while the old access_token is valid, the new one will not be given to us.

M
Maxim Vasiliev, 2014-07-28
@qmax

For server authorization (without involving the user through the browser), you need to use a different procedure:
vk.com/dev/auth_server

V
Vadim Klimenko, 2014-07-28
@Klimenko

error_reporting(E_ALL); output nothing?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question