Answer the question
In order to leave comments, you need to log in
How to extract the access_token array to make authorization through VK in php?
I have a problem that I can't extract the array that appears when following the link
example: https://oauth.vk.com/access_token?client_id=794994...
how can I extract it into a php variable?
code:
<?php
$client_id = "7949945";
$client_secret = "wrmYrwp41Ajf8c7tWvti";
$redirect_uri = " https://onetapped.ru ";
$auth = " https://oauth.vk.com/authorize?client_id=".$client... ";
$access_token = " https://oauth.vk.com/access_token?client_id=".$cli. .. '];
if(!$_GET['code']) {
echo " Login via VK ";
echo " access_token ";
}
?>
Answer the question
In order to leave comments, you need to log in
<?php
$app = array(
'client_id' => '',
'client_secret' => '',
'redirect_uri' => 'http://' . $_SERVER['HTTP_HOST'] . '/ИМЯ_ФАЙЛА.php'
);
if (!isset($_GET['code']))
echo '<a href="https://oauth.vk.com/authorize?client_id=' . $app['client_id'] . '&redirect_uri=' . urlencode($app['redirect_uri']) . '&response_type=code">Войти через ВКонтакте</a>';
else {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://oauth.vk.com/access_token?client_id=' . $app['client_id'] . '&client_secret=' . $app['client_secret'] . '&code=' . $_GET['code'] . '&redirect_uri=' . urlencode($app['redirect_uri']),
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
));
$data = json_decode(curl_exec($curl));
curl_close($curl);
if (isset($data->access_token)) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.vk.com/method/users.get?uids=' . $data->user_id . '&fields=uid,first_name,last_name,screen_name,sex,bdate,photo_big&access_token=' . $data->access_token . '&v=5.131',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
));
$data = json_decode(curl_exec($curl));
curl_close($curl);
if (isset($data->response[0]->id))
foreach ($data->response[0] as $key => $value)
echo $key . ': ' . $value . '<br/>';
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question