receiving this The redirect URI in the request: http://localhost did not match a registered redirect URI

4,313 views
Skip to first unread message

Dor Ben Dov

unread,
Jul 4, 2012, 3:53:33 AM7/4/12
to adsen...@googlegroups.com

Sérgio Gomes

unread,
Jul 4, 2012, 10:48:48 AM7/4/12
to adsen...@googlegroups.com
Hi Dor,

The registered URIs are controlled from your APIs Console project page. Under "API Access", you'll have a section called "Client ID for web applications". You'll be able to set your redirect URIs there.

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


---

Dor Ben Dov

unread,
Jul 10, 2012, 4:23:30 AM7/10/12
to adsen...@googlegroups.com
Sergio,
Why do i need the redirect, why can't i avoid it ? 


Dor

Sérgio Gomes

unread,
Jul 10, 2012, 6:52:48 AM7/10/12
to adsen...@googlegroups.com
Hi Dor,

I assume this is a web application you're building? The redirect or callback URL is used so that your application can get the auth data (it's part of the OAuth 2.0 protocol).

If you're building a desktop application instead, then you should set up an "installed application" client ID in your project instead.

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


----

Dor Ben Dov

unread,
Jul 10, 2012, 8:13:35 AM7/10/12
to adsen...@googlegroups.com
Sergio, 
Can i write a sample code, run it once, get the token, use it to get the authentication key. 
Save this token and authentication key. 
Use them to access adsense reporting api (my account) . 
Can also say that the authentication key or the token are permanent and won't be changed ? 


Regards,
Dor

Sérgio Gomes

unread,
Jul 10, 2012, 8:20:22 AM7/10/12
to adsen...@googlegroups.com
Hi Dor,

You can indeed. When you run the OAuth 2.0 flow with offline access enabled, you'll get back two tokens: an access token and a refresh token. The former is short-lived and used to make requests, whereas the latter can be used to request new access tokens.

You can save your refresh token to disk and use that to generate a new access token whenever you need to make requests. The refresh token won't stop working unless the user revokes access to your application.

Hope this helps!

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


---

Dor Ben Dov

unread,
Jul 10, 2012, 9:00:22 AM7/10/12
to adsen...@googlegroups.com
Hi,

Is there any simple way to create the access token ? 
Let's say i have the access token and the user (which is me) won't revoke the application. 
Can i use this access token with the adsense reporting api to retrieve my application data ? forever till it will be revoked ? 

Regards,
Dor

Sérgio Gomes

unread,
Jul 10, 2012, 9:12:57 AM7/10/12
to adsen...@googlegroups.com
Hi Dor,

Only the refresh token is long-lived. The access token expires after a short amount of time. You should save your refresh token (which will not expire) and generate new access tokens when you need them: https://developers.google.com/accounts/docs/OAuth2InstalledApp#refresh

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


---

Dor Ben Dov

unread,
Jul 10, 2012, 9:48:57 AM7/10/12
to adsen...@googlegroups.com
Hi Sergio,
Can i use the refresh token for all the ad sense reporting api access ? or do i need to do that with the access token. 
Each request should have a different token or can i use the same access token for all my request (which means that using the refresh token that saved i will get the access token for the specific session and use it for all the requests).

Regards,
Dor

Sérgio Gomes

unread,
Jul 10, 2012, 9:54:44 AM7/10/12
to adsen...@googlegroups.com
Hi Dor,

You need to use access tokens in your requests. You can generate them from your saved refresh token.

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


---

Dor Ben Dov

unread,
Jul 10, 2012, 9:59:57 AM7/10/12
to adsen...@googlegroups.com
Ok thanks great. 

Now for the first question again, where can i find a simple java code example on how to generate the refresh token. 

Then i will need to make another http call to get the access key right ? and then with it to make another http call to the ad sense reporting api right ? 


Thanks in advanced,
Dor

Sérgio Gomes

unread,
Jul 11, 2012, 8:29:52 AM7/11/12
to adsen...@googlegroups.com
Hi Dor,

It's easier if you just use the Java client library. Here's the client library guide: https://developers.google.com/adsense/management/complete_guide

The Java client library also has a number of samples for the AdSense Management API and other APIs, which you can adapt: http://code.google.com/p/google-api-java-client/wiki/APIs

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902


---
Reply all
Reply to author
Forward
0 new messages