googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.55k stars 2.37k forks source link

permissions.get() doesn't return a full Permission instance #2406

Closed Max-at-RDS closed 1 month ago

Max-at-RDS commented 1 month ago

Environment details

Steps to reproduce

  1. Create a Google Cloud project and enable Google Drive API
  2. Create a service account and associate the following scopes
  3. Use the service account impersonating a user account
  4. Make a request for a specific file using the 'permissions.get()' method

Code example

if __name__ == "__main__":
    session = getCredentials()
    drive = session.files().list().execute()
    for item in drive['files']:
        if(item['kind'] != 'drive#drive'):
            try:
                file = session.permissions().list(fileId = item['id']).execute()
                fileInfo = session.files().get(fileId = item['id']).execute()
            except HttpError:
                print("Something wrong happened")
            perms = file['permissions'][0]
            perm = session.permissions().get(fileId = item['id'], permissionId = perms['id']).execute()

Stack trace

Permission is : {'kind': 'drive#permission', 'id': 'XXXXXXXX, 'type': 'user', 'role': 'owner'}

The Permission instance doesn't include the fields described in the documentation

zstewar1 commented 1 month ago

I ran into this recently, and there appears to be a fields parameter you can pass to request specific fields in the response, e.g. session.permissions().get(fileId=someFile, permissionId=somePermission, fields='emailAddress').execute(). If you just want to get all fields, it appears to also work with fields='*'.

Max-at-RDS commented 1 month ago

This actually works. Thank you very much. Closing the issue.