T
T
thenull32021-08-23 03:56:03
PHP
thenull3, 2021-08-23 03:56:03

Getting a VK token does not work, what could be the problem?

There is such a file, vk-login.php:

<?php
define('ID', '79*****');
define('SECRET', '9LQ8**************S0');
define('URI', 'https://www.***********.com/admin/comp/vk-login.php');

if(!isset($_GET['code'])) { 
echo 'error';
exit;
}

$ouri = 'https://oauth.vk.com/access_token?client_id='.ID.'&client_secret='.SECRET.'&redirect_uri='.URI.'&code='.$_GET['code'].'&v=5.131';

$token = json_decode(file_get_contents($ouri), TRUE); 
if (!$token) {
    echo 'err';
} else {
    // что-то
}
?>

But during authorization, the token variable is empty, that is, it displays me on the err message.
The application settings themselves seem to be correct, I can even go to https://oauth.vk.com/authorize?client_id= ... and get back to vk-login.php, as I indicated in the login button itself.

<?php echo '<a href="https://oauth.vk.com/authorize?client_id='.ID.'&display=page&redirect_uri='.URI.'&scope=email&response_type=code&v=5.131">Войти</a>';  ?>


6122edde9f9a7498016588.png
6122f11ea6aed422640733.png
I tried other methods of authorization, everywhere there is a problem with the token. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-08-23
@HemulGM

Because the token does not come in the body. It is in the options after redirecting the authorization page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question