A
A
Alexander Ampleev2018-06-20 10:29:46
API
Alexander Ampleev, 2018-06-20 10:29:46

Why does wall.post stop working after a while?

I receive the token by hand, thus:
1) First

$sRequest = "https://api.vk.com/oauth/authorize?client_id=" . $vkontakteApplicationId . "&scope=offline,wall,groups&redirect_uri=https://vk.com&response_type=code";

- this can only be done by hand if you enter a link into the browser, as a result, the code is given in the url, from there I copy it with my hands and then I get a token:
2)
$sRequest = "https://oauth.vk.com/access_token?client_id=" . $vkontakteApplicationId . "&client_secret=" . $vkontakteApplicationSecret . "&redirect_uri=https://vk.com&code=" . $code;

3) I copy the received token and publish a post on the wall in the group like this:
$sRequest = "https://api.vk.com/method/wall.post?owner_id=" . $ownerID . "&from_group=1&access_token=" . $accessToken ."&signed=" . $signed . "&v=5.80";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $sRequest);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "message= $message");
        $r = curl_exec($ch);
        curl_close($ch);
        var_dump($r);

Yesterday everything worked ok somewhere at 16 Moscow time, today at 6:33 it no longer worked, it gave the error "User authorization failed: invalid session." - I understand that the token, probably, needs to be received by hand all the time? Or how? What exactly is the problem? Or, in principle, you can automate the receipt of a token using the same code (you only need to receive the code by hand, the token can be obtained automatically by this code - but here, too, there is a problem with the fact that if you do not contact for a long time, apparently, the session will also expire, i.e. i.e. you will have to make calls according to the crown and write the tokens to the database ..).
Thanks in advance for the replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ampleev, 2018-06-23
@Ampleev

In general, I wrote to vk.com support - they fixed it, now it works and nothing needs to be fixed.

V
Victor P., 2018-06-20
@Jeer

That's right, the token has a lifetime. As soon as it is expired, you need to get it again.
If you manage to get it by hand, then why can't you send a link from php and pull out a token from there? Unfortunately, I won’t tell you the code, I did it in another language. There should be examples of correct work, look

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question