How do I get a long-lasting oauth token for ruby access to campaign stats api

165 views
Skip to first unread message

Eric Berry

unread,
Mar 10, 2015, 6:28:43 PM3/10/15
to adwor...@googlegroups.com
I am writing an app which automatically imports cost data for adwords campaigns. This is something that runs in a Rails app and is triggered by a cron job. A user is not logged into the app in order for it to be triggered.

I have created an application-based client id and with it, generated an access token and refresh token.

Does this access token last or do I need to have something in my system refresh the token? If so, are there any examples of how to do this without an actual user clicking and pasting stuff? I'm certain this is a problem that others have solved already and I my head is starting to hurt trying to figure it out.

Thanks,

Eric

Josh Radcliff (AdWords API Team)

unread,
Mar 10, 2015, 6:45:52 PM3/10/15
to adwor...@googlegroups.com
Hi Eric,

As a starting point, I'd recommend using our Ruby client library if you are not already doing so.

Your use case is a great fit for offline access, which will give you a refresh token when the user accepts the OAuth prompt. With this refresh token, you'll be able to obtain new access tokens (the tokens you pass in your API requests) as needed.

Each access token expires in roughly one hour, but if you have a refresh token you can get a new access token without prompting the user again. The Ruby client library handles this process for you. All you have to do is configure your app with the refresh token as described here.

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages