OAuth 2.0 / PHP API / Reports

93 views
Skip to first unread message

Daniel Mayans

unread,
May 26, 2014, 10:39:57 AM5/26/14
to adsen...@googlegroups.com
Hello!

I'm generating some reports using the PHP AdSense API. 
I've tried out the adsense-sample.php and it works fine, but, I need to avoid the confirmation screen that requires to be logged with a Google account to access the reports.

Just like I do in AdWords, I need to preset all the credentials (client_id, client_secret, refresh_token) and generate a report without end-user interaction.

I've been reading about store the refresh token, and I got it, but I don't know how to use it properly inside the adsense-sample.php.



Thank you and sorry if my English isn't good!

Sérgio Gomes (AdSense API Team)

unread,
May 29, 2014, 4:53:29 AM5/29/14
to adsen...@googlegroups.com
Hi Daniel,

You'll need to get the refresh token from the client and store it in some form of persistence layer (a file in your server, or a database, for example). This page should help.

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

Daniel Mayans

unread,
Jun 3, 2014, 9:22:17 AM6/3/14
to adsen...@googlegroups.com
Maybe I haven't explained well:

Actually, I have stored the refresh token, but, I don't know how to use it inside this file to avoid the confirmation screen. Can I see an example of PHP code using the refresh token?

The page that you suggested me doesn't help. It doesn't says anything about how to use the refresh token.

Thank you!

Sérgio Gomes (AdSense API Team)

unread,
Jun 3, 2014, 9:35:01 AM6/3/14
to adsen...@googlegroups.com
Hi Daniel,

Apologies for that, I should have explained it a bit more clearly.

The "getAccessToken" method is actually a misnomer, as it retrieves both the access and refresh token (if available). Thus, in the sample you pointed to, what you're actually storing in the session is both the access and refresh tokens.
In order to make this fully persistent, all you would have to do would be to store them both in a database or local file, rather than in the session.

You would then retrieve them normally, and initialize the client with them.

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

Daniel Mayans

unread,
Jun 3, 2014, 9:51:04 AM6/3/14
to adsen...@googlegroups.com
Okey Sergio, thank you very much!
Reply all
Reply to author
Forward
0 new messages