André Casimiro
André Casimiro

Reputation: 153

Google spreadsheets api do not use OAuth2?

I'm trying to make authorized requests to the google spreadsheets API and all the examples I found requests email and password from the user.

Well this problem was solved with OAuth2 protocol which Google implements. I've gone through the OAuth2 process and I have a valid access_token, which I use to interact with Google Drive smoothly:

access_token = get_access_token() # external function
user_agent = request.META['HTTP_USER_AGENT']
credentials = AccessTokenCredentials(access_token, user_agent)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('drive', 'v2', http)
service.files().copy(fileId=k, body=dict(title="Copia")).execute() # this works!

But I can't figure out a way to use the access_token to interact with the spreadsheets API. Does it still uses email and password login?

Thanks!

PS: BTW, I'm using the python gdata package, and please let me know if you have a good reference for it! :)

Upvotes: 1

Views: 589

Answers (1)

André Casimiro
André Casimiro

Reputation: 153

So, if you already have an access token (maybe you got it by your own via Oauth2 protocol, like me). You can interact with google spreadsheet api passing an instance of AuthSubToken to methods of SpreadsheetsClient.

from gdata.gauth import AuthSubToken
from gdata.spreadsheets.client import SpreadsheetsClient

atok = AuthSubToken(token_string=get_access_token())  # acess token via protocol
data = SpreadsheetsClient().get_worksheets(key, auth_token=atok)

Upvotes: 2

Related Questions