0

Im using PHP to do my gmail API. So heres how my client its set.

$client = new Google_Client();
$client->setClientId('42XXXXXX3p0o9XXXXXXXXXXXXXXXXX.apps.googleusercontent.com');
$client->setClientSecret('XXXXXXrLXX22Ld-1XXXXXXX');
$client->setRedirectUri('https://mywebsite.com/AilaGmail/gmail.php'); 
$client->addScope('https://mail.google.com/');

When I click to login and authorize my API for the first time, I get this error:

**Error: redirect_uri_mismatch
Request Details
response_type=code
access_type=online
client_id=XXXXX-pXXXXXXX3.apps.googleusercontent.com
redirect_uri=https://mywebsite.com/AilaGmail/gmail.php
state=
scope=https://mail.google.com/
approval_prompt=auto**

Ive already tried some solutions like changing redirect_uri to 'postmessage', but then I got another error:

Error: invalid_request
origin parameter is required!

what can I do? Im using php! Please help...

edit 1* Ive tried more solutions like changing the client_secret.json file, but also did not work :/

  • It has probably something to do with the fact that your redirect_uri specified in the Google configuration panel is different from the one that you specify in the HTTP call – markvdlaan93 May 16 '18 at 21:10
  • Also, you can visit this [SO post](https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch) for further discussion why you are having that error. – MαπμQμαπkγVπ.0 May 17 '18 at 11:24
  • But i didnt find the Google configuration for this. When you select 'web application' its there, but there's no field for 'redirect uri' when you use PHP (the option 'other' in this case) – Guilherme Canoa May 17 '18 at 12:13

1 Answers1

0

OK guys, i did it. My code was missing one important parameter:

$client->setAuthConfig('client_secret.json');

I still having problems with how to use the code that i get, but the mismatch error is solved.