I am developing a PHP code that uses the Google Drive API, upload API files, when your The Google Account was the owner of the drive that was logged in. My question is, it is possible that it can upload files, even if the Google Account that is not owned by it, for example, no Google Account was logged in or another Google Account logged in Was there. I just want to say that the drive is public that any file can upload.
This is the code I used to have.
& lt ;? Php function setGoogleDriveUpload ($ clientID, $ secret keys, $ redirectory, $ newfilemen, $ upload file) {session_start (); $ Url_array = 'Explosion ('? ',' Http: //'.$_SERVER ['HTTP_HOST']. $ _ Server ['REQUEST_URI']); $ Url = $ url_array [0]; Need_once 'google-api-php-client / src / Google_Client.php'; Need_once 'google-api-php-client / src / contrib / Google_DriveService.php'; $ Client = new Google_Client (); $ Customer & gt; SetClientId ($ clientid); $ Customer & gt; SetClientSecret ($ secretKey); $ Customer & gt; SetRedirectUri ($ redirecturi); $ Customer & gt; SetScopes (array ('https://www.googleapis.com/auth/drive')); If (isset ($ _GET ['code'])) {$ _SESSION ['accessToken'] = $ client-> authenticate ($ _GET ['code']); Header ('location:' $ url.); Exit; } Elseif (! Isset ($ _ session ['access token'])) {$ client- & gt; Authenticate (); } $ Client- & gt; SetAccessToken ($ _ session ['AccessToken']); $ Service = new Google_DriveService ($ customer); $ Finfo = finfo_open (FILEINFO_MIME_TYPE); $ File = New Google_DriveFile (); $ File_path = $ uploadfile; $ Mime_type = finfo_file ($ finfo, $ file_path); $ File & gt; SetTitle ($ newfilename); $ File- & gt; Setdition ('this is a'. $ Mime_type. Document '); $ File & gt; SetMimeType ($ MIME_TYPE); $ Service- & gt; File-> Insert ($ file, array ('data' = & gt; file_gate_content ($ file_path), 'mimetype' => gt; $ mime_type); Finfo_close ($ finfo); }
No comments:
Post a Comment