3

I am new to the Google APIs and want to know how I would be able to access 2 different APIs within the same files.

I have

SCOPES = 'https://www.googleapis.com/auth/calendar'

but I also want

SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'

to be accessible from the same file. Does anyone have any idea how to go about doing this?

Thanks!

2 Answers 2

5

When you authenticate simply add both scopes. The user will be prompted to grant you access to both.

SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/calendar'

You may have to put a comma between them I a not sure it depends upon the library

Now I am not a python dev, however most of the Google client libraries are created the same. Assuming you are using that you will need to create both a calendar service and a drive service. You create them both using the same credential you got from above. Code ripped from here.

serviceDrive = discovery.build('drive', 'v3', http=http)
serviceCal = discovery.build('calendar', 'v3', http=http)

When you need to access calendar you use the calendar service when you need to access drive you use the drive service.

1
  • Thanks I will try this!
    – Jay
    Mar 3, 2017 at 18:37
2

Add scopes into a list object.

Example:

SCOPES = ['https://www.googleapis.com/auth/calendar',
          'https://www.googleapis.com/auth/drive.metadata.readonly']
1
  • 1
    Works for me, be careful when using official auth examples like in [1] - first: you may add additional scopes from the command line, the sript will take care of the rest, but if you add them directly to the code, you need to change the code, because configured scopes will be put into another list: "configured_scopes = [_SCOPE]" [1] github.com/googleads/google-ads-python/blob/master/examples/…
    – n.r.
    Sep 15, 2021 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.