php - Allow users to upload files to my google drive script -


i have forms can filed users , uploaded google drive. following code accomplishes task. however, asks permission user access drive, , uploads user's drive , not drive. want upload directly google drive.

how can allow script access drive? can use kind of hard-coded tokens or access tokens?

$client = new google_client(); $client->setapplicationname("drive api quickstart"); $client->setdeveloperkey("xxxxxxxxxxxx"); $client->setredirecturi("xxxxxxxx"); $client->setclientid('xxxxxxxxxxx'); $client->setclientsecret('xxxxxxxxxx'); $client->setscopes(array('https://www.googleapis.com/auth/drive')); $client->setaccesstype("online"); $client->setapprovalprompt("auto");  if (isset($_get['code'])) {     $client->authenticate($_get['code']);       $redirect = 'http://' . $_server['http_host'] . $_server['php_self'];     header('location: ' . filter_var($redirect, filter_sanitize_url));  }  if (!$client->getaccesstoken() && !isset($_session['token'])) {     $authurl = $client->createauthurl();     print "<center><a class='login text-center btn btn-primary' href='$authurl'>connect google upload file!</a></center>";      }        if (isset($_session['token'])) {     $service = new google_service_drive($client);     $file = new google_service_drive_drivefile();     $file->settitle($name);     $file->setdescription('document');     $file->setmimetype('application/pdf');     $data = file_get_contents('./uploads/'.$name);     $createdfile = $service->files->insert($file, array(           'data' => $data,           'mimetype' => 'application/pdf',           'uploadtype' => 'multipart'         )); 

you'll have check out service accounts. service accounts accounts belong application rather user. acts on user's behalf call apis they're accounts aren't involved.

this way, uploaded file go email set on service account can control. once done, can set share settings of service account main account this dev did.

hope helps!


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -