【发布时间】:2018-08-17 06:31:47
【问题描述】:
我正在尝试使用服务帐户访问 google team drive
1)我去了团队驱动器并添加为会员服务帐户电子邮件,并授予他完全访问权限
2) 我不确定必须(在控制台内)为此服务帐户授予哪个权限才能连接到 google team drive
这是我正在使用的代码
def initialize_analyticsreporting():
print("Wait for Initialising")
credentials = ServiceAccountCredentials.from_json_keyfile_name(
"key.json", "https://www.googleapis.com/auth/drive")
# Build the service object.
analytics = build('drive', 'v3', credentials=credentials)
print(analytics)
print("Service for Google Drive - Initialised")
return analytics
def main(analytics):
page_token = '1'
while True:
response = analytics.files().list(q="mimeType='image/jpeg'",
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
for file in response.get('files', []):
# Process change
print 'Found file: %s (%s)' % (file.get('name'), file.get('id'))
page_token = response.get('nextPageToken', None)
if page_token is None:
print("Token not initilied")
break
return response
if __name__ == '__main__':
analytics = initialize_analyticsreporting()
main(analytics)
身份验证部分工作正常。
它失败了,因为我不确定 page_token 是什么。
我需要什么:我需要使用此服务帐户连接到 Team Drive,并获取每个类别的文件数量,例如有多少视频、图片等(如果可能)
【问题讨论】:
标签: python google-drive-api google-drive-realtime-api service-accounts google-drive-shared-drive