Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Max-at-RDS opened this issue May 23, 2024 · 2 comments
Closed

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

Max-at-RDS opened this issue May 23, 2024 · 2 comments
Assignees

Comments

@Max-at-RDS
Copy link

Max-at-RDS commented May 23, 2024

Environment details

  • OS type and version: Ubuntu 22.04
  • Python version: 3.10.12
  • pip version: 22.0.2
  • google-api-python-client version: 2.119.0

Steps to reproduce

  1. Create a Google Cloud project and enable Google Drive API
  2. Create a service account and associate the following scopes
    - https://www.googleapis.com/auth/drive
    - https://www.googleapis.com/auth/userinfo.email
  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
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants