I'm trying to parse some data present in google sheets and I want to get the details about the owner of the google sheet as well (Like the owner's name, and maybe email ID as well). Is it possible to do that by using Google Sheet APIs ?
CodePudding user response:
You cant do it though the google sheets api. However if you go though the google drive api and do a file.get on the file you get something like this.
"owners": [
{
"kind": "drive#user",
"displayName": "XXXXX",
"photoLink": "https://lh3.googleusercontent.com/a-/AOh14GhkDDDZulUhea-c-7_eeZFaG8zpOnTHwYJE8=s64",
"me": false,
"permissionId": "XXXXX",
"emailAddress": "[email protected]"
}
],
Drive and sheets use the same scopes so you shouldn't need to authorize any additional scope to use the drive api. You will just need to create a drive service object similar to the one you have for sheets now.
service = build('drive', 'v3', credentials=creds)
pro tip with file.get makes sure you set fields = *
or id, owners
CodePudding user response:
As suggested by DalmTo, I could get the details by using Google Drive APIs.
After creating a drive service, the following code would get the owner details -
response = service.files().get(fileId=googlesheetid,fields='owners').execute()
response would contain data like this -
{"owners": [
{
"kind": "drive#user",
"displayName": "XXXXX",
"photoLink": "https://lh3.googleusercontent.com/a-/AOh14GhkDDDZulUhea-c-7_eeZFaG8zpOnTHwYJE8=s64",
"me": false,
"permissionId": "XXXXX",
"emailAddress": "[email protected]"
}]}