I want to set up a file store for my club, and I need to grant read-only access to members via our website. For lack of being able to integrate Google Drive on our website in an iframe, I picture the following scenario for granting member access:
Can this be done? It would seem so from reading https://developers.google.com/drive/service-accounts. Would I simply need to hard code the authorization code of my service account and then be able to count on it not changing? Or do I need more?
Thanks in advance.
Ok, it seems like this use case is doable. Note, however, that any given folder or file in Google Drive can be only shared with a maximum of 200 individual e-mail addresses.
Here's what I did: 1) Used the quickstart example https://developers.google.com/drive/quickstart-php to visit the auth URL, generate an auth code and use it to generate an access token by using:
$accessToken = $client->authenticate($authCode);
print_r($accessToken);
This code will print the contents of the access token in the browser/console as a JSON object. I am then able to use this JSON object for all future requests as long as the object contains a refresh token, which shouldn't expire.
I am then able to create an apiClient using the contents of my string containing the access token:
$credentials = '{json representation of access token}';
$apiClient = new Google_Client();
$apiClient->setUseObjects(true);
$apiClient->setAccessToken($credentials);
Finally, I'm able to make API calls to act on behalf of my user account.
I found this useful: https://developers.google.com/drive/auth/web-server