0
我已經使用完整的youtube api代碼插入commentthread youtube_v3,但是當我調用api時,它給了我下面的錯誤。
Authorization Required
You need to authorize access before proceeding.
當我點擊授權訪問其redired到谷歌的錯誤頁面,並顯示以下內容
400. That’s an error.
Error: redirect_uri_mismatch
Application: Application Name
You can email the developer of this application at: email address
The redirect URI in the request, http://localhost/done.php, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/******-*******.apps.googleusercontent.com?project=******* to update the authorized redirect URIs.
在這段代碼中,$_GET['code']
和$_SESSION['token']
未設置,使我無法獲得訪問令牌等等它給我redirect_uri_mismatch錯誤。
從哪裏設置值$_GET['code']
和$_SESSION['token']
。 代碼:
if (isset($_GET['code'])) {
if (strval($_SESSION['state']) !== strval($_GET['state'])) {
die('The session state did not match.');
}
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: ' . $redirect);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
給我的解決方案,如果你有先進的
感謝。
你爲什麼認爲錯誤與這段代碼有關?錯誤消息非常清楚。 – jeroen
是@jeroen,但是從$ _GET ['code']和$ _SESSION ['token']的值被設置? 我一行一行地寫出完美的代碼。 –