Good day! I wrote a script for automatic unloading of goods from the online store to photo albums and products in VK. Worn out, but the script works, everything is ok. Next, I need to write a cron, which will periodically update the information about the goods. When authorizing a user, he set scope offline so that the token is not limited by time.

At the first export, the user is authenticated and received a token. After the user confirms the access rights, the user data, including the token itself, I save to the database.

Further, when updating product information, I need to automatically update the product description, or photos (depending on which type of export the user has selected) using the crown. And here there was a problem: how to check if the token is valid? secure.checkToken returns an error when I try to check access_token: User authorization failed: invalid access_token

$params = array( 'uids' => $user_id, 'access_token' => $token ); $result = json_decode(file_get_contents('https://api.vk.com/method/secure.checkToken' . '?' . urldecode(http_build_query($params))), true); 

    1 answer 1

    First, I don’t really understand why you are trying to pass such parameters. For secure.checkToken it is stated that it takes two parameters: token (which is curious in itself, it may be necessary, and not the global access_token. Either of them. I can’t check now) and an optional ip. There are no uids, user_id is returned.

    The second point, urldecode after http_build_query is not needed. http_build_query generates the correct query string. The need to break it means only a gross violation of the standards by the second side, and vk, like with standards, is still considered.

    As a third point, I note that api without a mandatory indication of the version has been declared obsolete and will cease to work in a few months.

    On the question of how to check if the token is valid - you still have a response handler from api. There and check that quite specific error type error_code = 5 is returned to the rotten token.