Answer the question
In order to leave comments, you need to log in
Why does Ajax return an error after contacting the server?
Authorization through VKontakte, why does ajax return an error when making a request to the server?
Ajax is called from indexa.php file
Log:
XMLHttpRequest cannot load http://oauth.vk.com/authorize?client_id=5993817&redirect_uri=http://localhost/&response_type=code. Response for preflight is invalid (redirect)
<?php
$client_id = '5944817'; // ID приложения
$client_secret = 'CjHNgfgCDqfVJ6PrK3pa'; // Защищённый ключ
$redirect_uri = 'http://localhost/'; // Адрес сайта
$msgtoclient = '';
$url = 'http://oauth.vk.com/authorize';
$params = array(
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'response_type' => 'code'
);
$link = $url . '?' . urldecode(http_build_query($params));
header('Location:'.$link);
exit;
if (isset($_GET['code'])) {
$result = false;
$params = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'code' => $_GET['code'],
'redirect_uri' => $redirect_uri
);
$token = json_decode(file_get_contents('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true);
if (isset($token['access_token'])) {
$params = array(
'uids' => $token['user_id'],
'fields' => 'uid,first_name,last_name,screen_name,sex,bdate,photo_big',
'access_token' => $token['access_token']
);
$userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
if (isset($userInfo['response'][0]['uid'])) {
$userInfo = $userInfo['response'][0];
$result = true;
}
}
if ($result) {
$msgtoclient = $userInfo;
} else {$msgtoclient = 'sdsdsd';}
}
echo json_encode($msgtoclient) ;
?>
Answer the question
In order to leave comments, you need to log in
I have a couple of similar screenshots on pinterest:
https://pin.it/o7y72wqossmhsh
you can google it and see in the code which script is made
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question