I have used complete code of youtube api for insert commentthread youtube_v3 but when I call API it gives me below error.
Authorization Required
You need to authorize access before proceeding.
When I clicked on "authorized access" it redirects to google error page and displays below content:
- 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. Visithttps://console.developers.google.com/apis/credentials/oauthclient/******-*******.apps.googleusercontent.com?project=*******
to update the authorized redirect URIs.
In this code,the $_GET['code']
and $_SESSION['token']
are not set so that I cannot get access token so it gives me redirect_uri_mismatch
error.
From where the value of $_GET['code']
and $_SESSION['token']
are set.
Code:
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']);
}
How can I solve this?