Google drive api 此文件的权限不足(我知道它很旧,但是…)

Google drive api 此文件的权限不足(我知道它很旧,但是…),google-drive-api,Google Drive Api,我认为这是一个老问题,但我仍然无法在互联网上找到任何解决方案。请帮助我,非常感谢 我的情况如下: a。xxx@mycompany.com将文件夹共享到aaa@gmail.com b。aaa@gmail.com将文件(putty.bin)上载到此文件夹 就这些。我唯一需要做的就是“删除这个文件”。 我需要说“我已经使用服务帐户删除了这个文件,但没有工作。” 以下是我的python代码: import httplib2 import pprint import sys from apiclient

我认为这是一个老问题,但我仍然无法在互联网上找到任何解决方案。请帮助我,非常感谢

我的情况如下:

a。xxx@mycompany.com将文件夹共享到aaa@gmail.com

b。aaa@gmail.com将文件(putty.bin)上载到此文件夹

就这些。我唯一需要做的就是“删除这个文件”。 我需要说“我已经使用服务帐户删除了这个文件,但没有工作。”

以下是我的python代码:

import httplib2
import pprint
import sys

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

"""Email of the Service Account"""
SERVICE_ACCOUNT_EMAIL = 'xxxxxxxxxxxx@developer.gserviceaccount.com'

"""Path to the Service Account's Private Key file"""
SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'xxxxxxxxxxx.p12'

def createDriveService(user_email):
    """Build and returns a Drive service object authorized with the service accounts
    that act on behalf of the given user.

    Args:
    user_email: The email of the user.
    Returns:
    Drive service object.
    """
    f = file(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
    key = f.read()
    f.close()

    credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key, scope='https://www.googleapis.com/auth/drive', sub=user_email)
    http = httplib2.Http()
    http = credentials.authorize(http)

    return build('drive', 'v2', http=http)

drive_service = createDriveService('xxx@mycompany.com')

# List files
files = drive_service.files().list(
    q='trashed = false'
).execute()

target_file = None
for fitem in files['items']:
    if fitem['title'] == 'putty.bin':
        target_file = fitem
        break

print 'Delete %s' % target_file['id']
drive_service.files().delete(
    fileId=target_file['id']
).execute()
此python代码可以成功列出文件(包括putty.bin),但无法删除,错误为

Traceback (most recent call last):
  File "quickstart.py", line 48, in <module>
    fileId=target_file['id']
  File "/usr/local/lib/python2.7/dist-packages/oauth2client-1.4.10-py2.7.egg/oauth2client/util.py", line 137, in positional_wrapper
  File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.4.0-py2.7.egg/googleapiclient/http.py", line 729, in execute
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/1Bd2C2Xxcsls2anFfbVp2dsdtdSx? returned "Insufficient permissions for this file">
回溯(最近一次呼叫最后一次):
文件“quickstart.py”,第48行,在
fileId=target_文件['id']
文件“/usr/local/lib/python2.7/dist packages/oauth2client-1.4.10-py2.7.egg/oauth2client/util.py”,第137行,位于位置包装器中
文件“/usr/local/lib/python2.7/dist packages/google_api_python_client-1.4.0-py2.7.egg/googleapiclient/http.py”,第729行,在execute中
GoogleAppClient.errors.HttpError:

有人能帮我吗?

有aaa@gmail.com请记住修补他们上载的文件的权限xxx@mycompany.com访问该文件?默认情况下,当文件上载时,其仍然属于aaa@gmail.com,他们必须使用授予的权限修补该文件xxx@mycompany.com进入


问题要求:

否。但当我使用登录google drive时xxx@mycompany.com,我可以使用Web UI删除此文件。这不必aaa@gmail.com来修补这个文件。因此,我认为我也可以在这段代码中做同样的事情,righit?谁不能删除文件,然后服务帐户或xxx@mycompany.com服务帐户不可用xxx@mycompany.com它的xxxxxxxxxxxx@developer.gserviceaccount.com. 除非具有访问权限,否则无法删除该文件。xxxxxxxxxxxx@developer.gserviceaccount.com被授予mycompany.com的权限,因此我可以使用它列出中的所有文件xxx@mycompany.com谷歌硬盘。我还检查了文件权限,它显示“xxx@mycompany.com可以编辑”,并且当我以xxx@mycompany.com由webui提供。只有此代码不能。您介意尝试授予吗xxxxxxxxxxxx@developer.gserviceaccount.com访问该文件,然后让服务帐户尝试删除它。xxxxxxxxxxxx@developer.gserviceaccount.com不是xxx@mycompany.comI登录为aaa@gmail.com,然后是格兰特的xxxxxxxxxxxx@developer.gserviceaccount.com'可以编辑此文件。在此之后,我使用相同的代码(服务帐户xxxxxxxxxxxx@developer.gserviceaccount.com,及xxx@mycompany.com作为用户电子邮件),但仍然失败。