Search code examples
google-drive-apigoogle-appsservice-accounts

Determine the owner of a Google Drive document with a service account


I am looking for a way to retrieve the content of a Drive document on a Google Apps domain knowing nothing but the document ID.

I have a Service Account that can be authorized on the Google Apps domain for any required scope and can impersonate any user. The document can be owned by any user of the domain and is not necessarily shared with a specific account.

Is there any way more efficient than going through all the users one by one, checking if they have access to the said document, and if yes retrieve the document's content? Worst case scenario, I will have to go through all the users before being able to open the document, which can be quite heavy.

If I had a way to quickly determine the owner of a document, I could impersonate him and get the content easily.

Thanks a lot,


Solution

  • For security reasons, users who have no access to the document won't be able to see any details about the document including owner. Thus your only option is to loop over each and every user.

    If you have Google Apps Unlimited or Google Apps for EDU, you may be able to use the Reports API to get a better idea of which users in your domain may have viewed or edited the document giving you a clue about who has access. To do this, you would list the Drive activities and include the doc_id in the filter attribute.