Friday 15 June 2012

php - Is it possible to allow a site's any registered user or an annoymous user to upload file to my google drive -



php - Is it possible to allow a site's any registered user or an annoymous user to upload file to my google drive -

i have read so:how upload google drive account, not users

and found possible, though hence decide not utilize service business relationship , utilize own google account's drive space instead.

however, found difficulties in understanding exact steps accomplish this. read oauth2.0, drive api, , cros-upload sample google.

but not know how proceed create upload drive instead of when user logged in google+, become uploading own drive.

i wonder if know exact knowledge should obtaining , steps , implementation required accomplish uploading file registered users google drive drive api. using php bakend , angularjs front-end. so, if made possible easier either method or existing lib (which can't find except drive's doc on this), ideal, steps build 1 wonderful well.

more detail, in post showed on top, 2nd answer's phrase of "do one-off auth refresh token, store. can utilize time generate access token needed invoke actual drive api. can generate refresh token using oauth playground, no need write code." me not clear steps involved , api should using accomplish it.

thank you

to send files google drive, need access token utilize drive user's storage, token expires in few moments creation.

to create access token, need refresh token, not expire. key doing this.

here simple file upload illustration using php api:

https://github.com/numsu/google-drive-sdk-api-php-insert-file-parent-example

set next readme.

to edit code send files single drive anywhere, need destination drive's refresh token, in case yours. logging in service , granting privileges on google consent screen. saved in $_session["credentials"]. var_dump() on , save refresh token somewhere, in file or database can access it.

you can remove points user logging in oauth, doesn't need that.

next need access token refresh token have. can google api function $client->refreshtoken($refreshtoken);

next need generate new drive service class using $client variable: $service = new google_service_drive($client);

after that, upload file:

$file = new google_service_drive_drivefile(); $file->settitle($title); $file->setmimetype($mimetype); $data = file_get_contents($filename); $createdfile = $service->files->insert($file, array( 'data' => $data, 'mimetype' => $mimetype, ));

good luck!

php google-drive-sdk google-oauth

No comments:

Post a Comment