Reputation: 588
I'm using a service account with a project that has both GoogleDrive and Google Sheets API enabled. I am trying to add permissions to an already existing Google Sheet (created by the same service account). The API is returning like it succeeds but the permissions remained unchanged.
Client config:
from googleapiclient.discovery import build
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
GOOGLE_CLIENT = build('sheets', 'v4', credentials=creds)
GOOGLE_DRIVE_CLIENT = build('drive', 'v3', credentials=creds)
using Google Drive V3 API:
new_permission = {
'type': "user",
'emailAddress': '[email protected]',
'role': "writer"
}
response = GOOGLE_DRIVE_CLIENT.permissions().create(
fileId=GOOGLE_SHEETS_ID, fields='*', body=new_permission).execute()
The response I get is:
{'kind': 'drive#permission', 'id': '1X2680991XXX793XX1308', 'type': 'user', 'emailAddress': '[email protected]', 'role': 'writer', 'displayName': 'Jeff Bezos', 'deleted': False}
Then I run list permissions but it returns empty:
permissions = GOOGLE_DRIVE_CLIENT.permissions().list(fileId=GOOGLE_SHEETS_ID).execute()
print(permissions.get('items', []))
Upvotes: 0
Views: 133
Reputation: 201378
If my understanding is correct, how about this answer? In your script, Drive API v3 is used. But from permissions.get('items', [])
, it seems that you are trying to use Drive API v2. By this, the empty array is returned. So how about the following modification?
permissions = GOOGLE_DRIVE_CLIENT.permissions().list(fileId=GOOGLE_SHEETS_ID).execute()
print(permissions.get('items', []))
permissions = service.permissions().list(fileId=fileId, fields='*').execute()
print(permissions.get('permissions', []))
If I misunderstood your question and this was not the direction you want, I apologize.
Upvotes: 3