@pinoyyid said all that is, and inspired him, here is the actual solution I came up with:
If you want to upload a file, you need two variables - oAuthToken and fileId
oAuthToken you receive from the client side JS when the user authenticates. If you use the example from google docs ( https://developers.google.com/picker/docs/ ), the function looks like this:
function handleAuthResult(authResult) { if (authResult && !authResult.error) { oauthToken = authResult.access_token; oauthToken;
fileId you get when the user selects a file. Again, a modified example from google docs:
function pickerCallback(data) { if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) { var doc = data[google.picker.Response.DOCUMENTS][0]; alert('You picked fileId: ' + doc[google.picker.Document.ID]); } }
You will probably pass this data as a form request or through ajax. A simple cURL call from the backend to upload a file:
$oAuthToken = 'ya29.XXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXX-XXXXXXX-XXXXXX-X-XXXXXXXXXXXX-XXXX'; $fileId = '0B4zzcXXXXXXXXXXXXXXXXXXXXXX'; $getUrl = 'https://www.googleapis.com/drive/v2/files/' . $fileId . '?alt=media'; $authHeader = 'Authorization: Bearer ' . $oAuthToken ; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $getUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, [ $authHeader , ]); $data = curl_exec($ch); $error = curl_error($ch); curl_close($ch); file_put_contents("destination-file.jpg", $data);
File upload docs: https://developers.google.com/drive/web/manage-downloads
source share