Почему я получаю несанкционированную ошибку ответа от Google Oauth?Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Почему я получаю несанкционированную ошибку ответа от Google Oauth?

Сообщение Anonymous »

Я сделал функцию, которая пытается получить токен доступа от токена обновления, но я получаю ошибку: < /p>
Error: Failed to get access token, HTTP code: 401, response: { "error": "unauthorized_client", "error_description": "Unauthorized" }
Я попытался проверить URL с ключами на https://reqbin.com/, но там я также получаю несанкционированную.function get_google_access_token() {
$client_id = 'x';
$client_secret = 'x';
$refresh_token = 'x';

$url = "https://oauth2.googleapis.com/token";

$data = [
"grant_type" => "refresh_token",
"client_id" => $client_id,
"client_secret" => $client_secret,
"refresh_token" => $refresh_token,
];

$options = [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
];

$curl = curl_init();
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpcode !== 200) {
throw new Exception("Failed to get access token, HTTP code: $httpcode, response: $response");
}

$result = json_decode($response, true);
if (!isset($result['access_token'])) {
throw new Exception("No access token found in response");
}

return $result['access_token'];
}

try {
$accessToken = get_google_access_token();
echo "Access Token: " . $accessToken;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}



Подробнее здесь: https://stackoverflow.com/questions/796 ... ogle-oauth
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»