Using existing access tokens with oauth2client
Posted on 2015/01/01
Was recently pulling my hair for a hour to figure out how I can use a existing access token I might have from somewhere else in my application with the Google API Client.
And after much searching, happened on
AccessTokenCredentials which is explained shortly at https://developers.google.com/api-client-library/python/guide/aaa_oauth#AccessTokenCredentials. With the very vague description of:
The oauth2client.client.AccessTokenCredentials class is used when you have already obtained an access token by some other means. You can create this object directly without using a Flow object.
Awesome that's what I need. But HOW ?
After looking at the docs and source code I managed to get it working by using the following sample:
at_credentials = AccessTokenCredentials(access_token_str, 'some-useragent/1.0') http = httplib2.Http() http = at_credentials.authorize(http)
Hope this saves someone a bit of trouble. No go and call some Google API's !
Also rather important if you are using the library like this on App Engine be sure to read the section on ThreadSafe for the library ... - https://developers.google.com/api-client-library/python/guide/thread_safety
What's currently keeping me busy
Testing and keeping websites safe
Tech/product of new incubating startups
Advocate and educate on the Google Cloud
Easy prescribed book management
Loadshedding being constantly updated and watched
Secret management for PAAS
National microchip database
Youtube channel of edited meetup talks
Gaming Youtube Channel