Drive API access to document with service account

断了今生、忘了曾经 提交于 2019-12-19 11:55:30

问题


I'm attempting to access a spreadsheet that's under the "google.com" domain using the Google Drive Java API through a service account. I need to export several of the worksheets contained within the document.

I've been able to create and use a service account (used via the Java API) but am not sure how to go about access, or if what I'm trying to do is even viable. I saw the following page: https://developers.google.com/drive/web/delegation but it seems highly unlikely that a service account I'm working with will be granted access to the google.com corporate domain. Our account contact at Google suggested we check the forums for some advice.

Given this, I have a couple of questions about approach:

  • Am I misunderstanding the access requirements? More specifically is there a way to grant a service account access to a specific document?
  • Is this task (worksheet export) better suited to the Spreadsheets API? That API seemed focused on operating within a spreadsheet, and the drive API seems to deal with file/document management.
  • Will a copy of the document to a different domain be required?

My guess is that we will need to copy the document, but I wanted to be sure, and to make sure that I'm understanding the APIs and access correctly.

Thanks!


回答1:


Do you have access to the file? try to use the method files.get https://developers.google.com/drive/v2/reference/files/get if you receive a 200 response then you have access, try to find the parameter exportlinks with those links you can export the file to different formats. otherwise you won't be able to do it.

  • Only people that have been granted access to the file, can access it. in the case of service account with delegation approved by the domain admin, the service account can impersonate people in that domain. if the user it is impersonating does not have access to a certain file, the service account wont have access either.

  • To export the file is better with the Drive API, as you mentioned the Spreadsheets API is to manage the content of the spreadsheet.

  • If you want to modify the information without modifying the original file, then yes.

hope this helps.




回答2:


You also have to grant the service account in the drive file you want to access to. Just Share the document you want to get access with the EMAIL ADDRESS that appears in the Google Developers Console (e.g. XXXXX@developer.gserviceaccount.com)



来源:https://stackoverflow.com/questions/28241799/drive-api-access-to-document-with-service-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!