I’m managing over 100 Google Sheets documents that are shared with many users. I need to clean up the access permissions by removing people who haven’t actually made any changes to the sheets. Can Python help me get a list of users who have actively edited each sheet by checking the revision history?
I’ve been using the gspread library to connect to the sheets, but I can’t figure out how to retrieve the contributor information from the edit history.
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
# Set up Drive Activity API access
activity_scope = ['https://www.googleapis.com/auth/drive.activity.readonly']
credentials = ServiceAccountCredentials.from_json_keyfile_name('service_key.json', scopes=activity_scope)
activity_service = build('driveactivity', 'v2', credentials=credentials)
user_actions = activity_service.activity().query(body={"filter":"detail.action_detail_case:EDIT",
"itemName":"items/abc123",
"consolidationStrategy":"legacy"}).execute()
# Set up People API access
people_scope = ['https://www.googleapis.com/auth/contacts.readonly']
people_creds = ServiceAccountCredentials.from_json_keyfile_name('service_key.json', scopes=people_scope)
people_service = build('people', 'v1', credentials=people_creds)
user_info = people_service.people().get(resourceName='people/9876543210',personFields='names,emailAddresses').execute()
When I try to get user details using the People API, I only get back this limited response:
{'resourceName': 'people/9876543210',
'etag': '%EgcBAj0JPjcuGgQBAgUH'}
Why is the email address missing from the response? Am I missing something in my API call?