Google Drive help required access to own Drive acc

2020-05-09 18:14发布

问题:

I want to access my own google drive on web page but allow anyone to upload files and restrict download access or show only limited file to user for downloading.

Drive API assumes that I will access another users credentials. But what I want is opposite, anyone can view my files (restricted what to view) but is free to upload. I have google nearly 6+ hours and didn't found any solution

Any Help Appreciated Thanks

回答1:

You say "Drive API assumes that I will access another users credentials" but this isn't correct. Calls to Drive include an Access Token, and it is that which determines which Drive account the call will access. Drive makes no assumptions about how that Access Token was obtained or which account it refers to.

All of the examples show how an Access Token is obtained for an end user, since that is the more complex flow. Your requirement is very much simpler.

All you need to do is:-

  1. Obtain a refresh token (see How do I authorise an app (web or installed) without user intervention? (canonical ?))
  2. Store that refresh token in your PHP application. Make sure it's secure
  3. When you need to access your Drive account, use the refresh token to obtain an access token as described at https://developers.google.com/accounts/docs/OAuth2WebServer#refresh