如何使用服务账户访问Google Drive修订API?

huangapple go评论63阅读模式
英文:

How do I access Google Drive Revisions API using a service account?

问题

当我想要获取文件更改时,我收到以下错误消息:

用户对文件 *** 没有足够的权限

我的代码:

SCOPES = ['https://www.googleapis.com/auth/drive']
credentials = service_account.Credentials.from_service_account_file(
    'service.json', scopes=SCOPES)
service = build('drive', 'v3', credentials=credentials)
service.revisions().list(fileId=DOC_ID)

IAM:

如何使用服务账户访问Google Drive修订API?

附注:此文件是由我在docs.google.com中创建的。

英文:

When I want to get file changes, I get the following error:

The user does not have sufficient permissions for file ***

My code:

SCOPES = ['https://www.googleapis.com/auth/drive']
credentials = service_account.Credentials.from_service_account_file(
    'service.json', scopes=SCOPES)
service = build('drive', 'v3', credentials=credentials)
service.revisions().list(fileId=DOC_ID)

IAM:

如何使用服务账户访问Google Drive修订API?

P.S.: This file was created by me in docs.google.com.

答案1

得分: 1

答案这个问题,因为它是在评论中添加的。错误信息"The user does not have sufficient permissions for file ***"通常指的是文件的权限问题。要解决这个问题,你应该与服务账号共享文件。这是基于Google文档中的说明这里

英文:

Answering the question, since it was added in the comment. The error message "The user does not have sufficient permissions for file ***" usually refers to a problem with the permissions in the file. To solved the issue you should share the file with the services account. This is base in the Google Documentation here

huangapple
  • 本文由 发表于 2023年2月14日 01:49:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定