问题描述
我是Google API的新手,想知道如何在同一文件中访问2个不同的API.
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.
我有
SCOPES = 'https://www.googleapis.com/auth/calendar'
但我也想要
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?
谢谢!
推荐答案
进行身份验证时,只需添加两个作用域即可.系统将提示用户授予您对两者的访问权限.
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'
您可能必须在它们之间加上逗号,但我不确定这取决于库
现在我不是python开发人员,但是大多数Google客户端库都是以相同的方式创建的.假设您正在使用,则需要同时创建日历服务和驱动器服务.您可以使用从上方获得的相同凭据来创建它们.从此处翻录的代码.
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.
这篇关于如何通过Google日历+ Google云端硬盘使用多个范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!