Skip to content

Instantly share code, notes, and snippets.

@briedis
Created September 22, 2015 06:51
Show Gist options
  • Save briedis/797ecd2eaef458573d15 to your computer and use it in GitHub Desktop.
Save briedis/797ecd2eaef458573d15 to your computer and use it in GitHub Desktop.
$url = 'https://www.googleapis.com/drive/v2/files/' . urlencode($_POST['googleFileId']) . '?alt=media';
$oAuthToken = $_POST['oAuthToken'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// If google drive file download, we need the token
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $oAuthToken]);
$data = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_errno($ch);
curl_close($ch);
file_put_contents('filename.jpg', $data);
@moos
Copy link

moos commented Jan 12, 2016

Thanks. Alternative curl command:

curl -O -J -H "Authorization: Bearer ya29wL.....access....token....L5u" "https://www.googleapis.com/drive/v2/files/0B9...file....id....tdlE?alt=media"

@mhieupham
Copy link

thanks you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment