How upload to MY Google Drive account, not the use

2019-03-05 11:49发布

问题:

Scenario:

Someone comes to my website and they see a file select field. They select the file and upload the file to MY Google Drive account.

Problem:

In looking at the Google Drive SDK docs I see that it uses OAuth for authentication, but I don't need to authenticate the user because they are uploading to MY Google Drive account. I'm aware that I need to register my application with Google, etc. but I'd like to know if I can upload without authorizing the user with OAuth the typical way (sending offsite or modal window to validate w/ redirect URL).

Is this possible to do? I'm using PHP.

回答1:

You have two options:-

  1. Use a Service Account. The files will be uploaded to the account of the Service Account

  2. Use a regular Google account. For this option, you (as the account owner) will need to do a one-off auth to get a refresh token, which you will store. You can then use this any time to generate the access token needed to invoke the actual Drive API. You can generate the refresh token using the Oauth Playground, so no need to write any code.

See How do I authorise an app (web or installed) without user intervention? (canonical ?)