Error: redirect_uri_mismatch and Error: invalid_grant

2,254 views
Skip to first unread message

Doubt Dolson

unread,
Jan 10, 2014, 7:54:53 AM1/10/14
to adwor...@googlegroups.com
Hi,

As we were trying to get API access, we did follow the following procedure but with only failure.

We got error messages at two places while

1. Trying to get Authorization Code 'Error: redirect_uri_mismatch'
2. Trying to get Refresh Token 'Error: invalid_grant'
 

--------CASE # 1 :
   We have an active MCC account
   We are using Adwords PHP Client Library v201309
   We have valid and approved developer token
   We have generated client_id and client_secret using  URL : https://code.google.com/apis/console#access for Web Application
   We went to command line and executed GetRefreshToken.php
   We got URL to execute
   We  executed ,we got error #1'Error: redirect_uri_mismatch'

--------CASE # 2 :
   From case # 1, We got URL to execute
   We replaced redirect_uri manually by replacing with one of the urls defined as redirect urls during client id/secret generation
   We executed the modified URL
   We got an interface where it asked if we want to allow access to the application we defined
   We allowed Clicked on allow button
   We got an authorization code
   We supplied the same to the GetRefreshToken.php file as $code
   Again, we got an error 'Error: invalid_grant'
  
We are not able to move ahead from this point. So, any help would be appreciated.

Note:
    With the same developer token, we are able to fetch data from a test MCC Account.

Thanks,
Deepak

Ray Tsang (AdWords API Team)

unread,
Jan 14, 2014, 1:56:02 PM1/14/14
to adwor...@googlegroups.com
Deepak,

In your use case, I feel you should create a client ID / secret pair for Installed application.  Please see our OAuth 2.0 authentication guide for more detail.

Once you are using an Installed application - PHP's GetRefreshToken.php should work as expected.

Thanks,

--
Ray Tsang (AdWords API Advisor)

Doubt Dolson

unread,
Jan 16, 2014, 5:38:43 AM1/16/14
to adwor...@googlegroups.com
Hi Ray,

 I was not able to create with any type of client.

But, I could get the refresh token using Oauth playground interface.

Thank you.

Deepak

Ray Tsang (AdWords API Team)

unread,
Jan 16, 2014, 3:18:17 PM1/16/14
to adwor...@googlegroups.com
Deepak,

If you were able to get the OAuth Playground interface, it most likely means you have created an OAuth 2.0 Web application.  This is perfectly fine if you plan to be able to operate on multiple user credentials.

In most cases though, you may have a single top level MCC that manages the AdWords accounts.  In which case, I would recommend you create an OAuth 2.0 Installed application to use with your PHP web application.

Cheers,

--
Ray Tsang (AdWords API Advisor)


Doubt Dolson

unread,
Jan 17, 2014, 10:03:19 AM1/17/14
to adwor...@googlegroups.com
Hi Ray,

Thank you very much for the reply.

Yes, you guessed it right, we created an Web application client.

In our case, it is not just multiple accounts under one MCC account but we have multiple MCC accounts. So, could you suggest us how we should go ahead in terms of authentication [OAuth2] like getting refresh tokens ? Let's say we have 10 MCC accounts and all those 10 contains multiple accounts under them.

Regards,
Deepak

Ray Tsang (AdWords API Team)

unread,
Jan 17, 2014, 2:38:33 PM1/17/14
to adwor...@googlegroups.com
Deepak,

Thanks for the clarification!  That really helps me as well.  The answer really depends.

For example, if you can link the 10 MCC accounts under a single MCC account that you have access to - then you can simply obtain a refresh token for your top level MCC account and still being able to access all of the sub-MCC accounts.

If you do it this way, you can register an OAuth 2.0 Installed application even if you are writing a web application.

Alternatively, you can also do what you are currently doing - but to access each MCC accounts it needs to be authorized by a corresponding user.

I'd say the formal is much simpler to implement if you can link those accounts under a single MCC.

Thanks!

--
Ray Tsang (AdWords API Advisor)

Akhmad Bayquni

unread,
Mar 28, 2015, 1:51:48 PM3/28/15
to adwor...@googlegroups.com
Can i know what you do in case 1? I have same problem. And it my first time for using Adwords API. I need help. :)

Doubt Dolson

unread,
Mar 30, 2015, 3:01:40 AM3/30/15
to adwor...@googlegroups.com, akhmad....@gmail.com
It seems there is problem with GetRefreshToken.php (at least with the version we were using). So,

Forget about execution of GetRefreshToken.php
Instead, go to this URL : https://developers.google.com/oauthplayground/
Click on the SETTINGS icon on top right
CHECK mark Use your own OAuth credentials
Provide "OAuth Client ID" and "OAuth Client Secret" you have
Click on close
Next, on

Step 1Select & authorize APIs

Fill the input box(the box with watermark text 'Input your own scopes' with "https://adwords.google.com/api/adwords/"

Then, click on Authorize APIs

Now,

Step 2Exchange authorization code for tokens


The above step will be populated with Authorization Code

Again click on Exchange authorization code for tokens in the same step

The required Refresh Token and Access Token gets populated


The same can be used on your client applications to consume ADWORDS APIs


Hope this works. If not, let me know with specifications, I will be glad to have a look.



--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "AdWords API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-api/pv9y3nTI89s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-api...@googlegroups.com.
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/0ae076d5-8bb0-49f3-a0a5-905f712f08b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Akhmad Bayquni

unread,
Mar 30, 2015, 3:31:49 AM3/30/15
to adwor...@googlegroups.com, akhmad....@gmail.com
Hi, thanks for the response. I've done what you mean, but the same problem comes even as the first step.

I've been checking the "Use your own OAuth credentials", i was provide "OAuth Client ID" and "OAuth Client Secret" where i have.

I was fill the input box (the box with the watermark text 'Input your own scopes' with "https://adwords.google.com/api/adwords/" and when I click "Authorize APIs" I redirected to the page with the error the same. 400.

That's an error.

Error: redirect_uri_mismatch

The redirect URI in the request: https://developers.google.com/oauthplayground did not match a registered redirect URI.

Just for info, i installed this on my localhost with xampp and phph 5.4.

In the dashboard API I set JavaScript origins at: http://localhost:8700 and Redirect URIs with http://localhost:8700/ads (this is the folder where I put all the files adwords-examples-and-lib-5.8.2.tar.gz)

Doubt Dolson

unread,
Mar 30, 2015, 9:36:16 AM3/30/15
to adwor...@googlegroups.com
Hi then the issue lies on the client creation ........specially in setting of redirect_url

Reply all
Reply to author
Forward
0 new messages