0

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:

  1. 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.

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Arshad Shaikh
  • 564
  • 1
  • 3
  • 13
  • Why do you think that the error is related to that piece of code? The error message is pretty clear. – jeroen Sep 06 '16 at 06:50
  • Yes @jeroen but from where the value of $_GET['code'] and $_SESSION['token'] are set? I write the perfect code line by line. – Arshad Shaikh Sep 06 '16 at 06:57

1 Answers1

0

Based from this thread, the redirect URI where the response is returned to has to be registered in the APIs console, and the error is indicating that you haven't done that, or haven't done it correctly.

Go to the console for your project and look under API Access. You should see your client ID & secret there, along with a list of redirect URIs. If the URI you want isn't listed, click edit settings and add the URI to the list.

You can also check on these related SO questions:

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59