Combining Google API and Google Drive auth

I have an app that needs to both use the Google REST API and the user’s Google Drive files. Since I need to authorise the request for the specific API scopes that I need, it would be nice to be able to roll the Drive API scope auth into the one big authorisation (rather than having the user need to authorise the app twice). But I can’t quite find a way to authorise google.drive with a pre-existing google.auth token.

Oh, yes - simple oversight there. I’ve updated google.drive.login() to accept a list of scopes just like google.auth.login() can; that will go live in the next couple of days.

In the meantime, you can pass the Drive scopes directly to google.auth.login() as a workaround:

google.auth.login(["https://www.googleapis.com/auth/drive", 'http://spreadsheets.google.com/feeds/'])

(And of course, you can then add all the extra scopes you want!)

Hope that helps :slight_smile:

1 Like

Thanks for the quick response!

Sorry; I could have been a little clearer. I want the app to be able to access a user’s files (using google.drive.get_user_files() etc), using an existing access token that I’ve gotten through google.auth.refresh_access_token(refresh_token). I’ve already worked out how to pass the Drive scopes to google.auth.login() but that doesn’t allow me to use the access token from google.auth.refresh_access_token() to call the google.drive functions.

If the google.drive module has refresh_access_token functionality, then I guess I could use that once your changes come through, but conceptually it’s backwards.

Incidentally, autocomplete doesn’t seem to be working in the IDE for google.drive right now (or when I tried this initially); I’ve tried reloading, and it seems to have the problem in all projects (including a freshly created one). Other autocomplete, including google.auth works fine.

1 Like