Google drive api 通过python使用Google Drive API V3获取Google Drive文件所有者电子邮件地址

Google drive api 通过python使用Google Drive API V3获取Google Drive文件所有者电子邮件地址,google-drive-api,Google Drive Api,我无法通过Google Drive API v3获取Google Drive上文件的所有者 我可以在v2下这样做,但事情已经改变了 根据计划,我需要: 列出文件的权限(没问题) 从该权限列表中查找具有“所有者”角色的权限Id(没有问题) 得到许可。。。它应该返回一个权限资源,该资源应该包括电子邮件地址(问题!) 不幸的是,我得到的是一些信息,但不是电子邮件地址 我怀疑我需要更改我的“get”调用来告诉API我要查找哪些字段,但我不知道如何做到这一点 这就是我得到的(v3): 不幸的是,我得到了一

我无法通过Google Drive API v3获取Google Drive上文件的所有者

我可以在v2下这样做,但事情已经改变了

根据计划,我需要:

  • 列出文件的权限(没问题)
  • 从该权限列表中查找具有“所有者”角色的权限Id(没有问题)
  • 得到许可。。。它应该返回一个权限资源,该资源应该包括电子邮件地址(问题!)
  • 不幸的是,我得到的是一些信息,但不是电子邮件地址

    我怀疑我需要更改我的“get”调用来告诉API我要查找哪些字段,但我不知道如何做到这一点

    这就是我得到的(v3):

    不幸的是,我得到了一个“KeyError:‘emailAddress’”(如果我查看“p”的内容,有角色、种类、类型和id,但没有电子邮件地址)

    这适用于我(使用v2):


    太简单了。。。只需将以下内容添加到get调用:

    ,fields='emailAddress'

    i、 e


    带驱动器API v3的脚本似乎有
    返回构建('Drive','v2',http=http\u auth)
    。Oops。。。剪切和粘贴错误(在我的脚本中为“v3”)。向请求中添加字段=*将返回所有元数据。谢谢。。。很高兴知道!
    from oauth2client.service_account import ServiceAccountCredentials
    from httplib2            import Http
    from apiclient.discovery import build
    
    def build_service(user):
      keyfile = 'C:\Python27\Scripts\Certificates for Transfer owner script\Transfer Ownership on Drive-f240cff252af.json'
      SCOPE = 'https://www.googleapis.com/auth/drive'
      credentials = ServiceAccountCredentials.from_json_keyfile_name(keyfile, scopes=SCOPE).create_delegated(user)
      http_auth = credentials.authorize(Http())
      return build('drive', 'v2', http=http_auth)
    
    service = build_service('lpglobaldrive@lonelyplanet.com.au')
    f = service.files().get(fileId='1lASRBuAHRxEC-T0X5SdlF3w7X_168Q2QV9L0V6QaXUk').execute()
    
    p = service.permissions().get(fileId='1lASRBuAHRxEC-T0X5SdlF3w7X_168Q2QV9L0V6QaXUk',permissionId='18137907375963748644').execute()
    currentOwner = p['emailAddress']
    
    from oauth2client.service_account import ServiceAccountCredentials
    from httplib2            import Http
    from apiclient.discovery import build
    
    def build_service(user):
      keyfile = 'C:\Python27\Scripts\Certificates for Transfer owner script\Transfer Ownership on Drive-f240cff252af.json'
      SCOPE = 'https://www.googleapis.com/auth/drive'
      credentials = ServiceAccountCredentials.from_json_keyfile_name(keyfile, scopes=SCOPE).create_delegated(user)
      http_auth = credentials.authorize(Http())
      return build('drive', 'v2', http=http_auth)
    
    service = build_service('lpglobaldrive@lonelyplanet.com.au')
    f = service.files().get(fileId='1lASRBuAHRxEC-T0X5SdlF3w7X_168Q2QV9L0V6QaXUk').execute()
    
    currentOwner = f['owners'][0]['emailAddress']
    
    currentOwner = service.permissions().get(fileId='1lASRBuAHRxEC-T0X5SdlF3w7X_168Q2QV9L0V6QaXUk',permissionId='18137907375963748644',fields='emailAddress').execute()['emailAddress']