Answer the question
In order to leave comments, you need to log in
How to programmatically download an image from a Google Drive shared link?
1. There is a link of the form: https://drive.google.com/file/d/1SXjHil-G3rjgOpWEr... , it is open to everyone (this file is not on my Google Drive).
2. I connected the Google Drive API to my Google Drive, I have a token, I see my files, everything is fine here.
3. What method can be used to download the image from the link in step 1 using the Google Drive API?
Answer the question
In order to leave comments, you need to log in
Everything turned out to be much easier. There is a link https://drive.google.com/uc?export=download&id=DRI... where you can substitute the file id from the shared link.
Then just CURL:
$ch = curl_init('https://drive.google.com/uc?export=download&id=DRIVE_FILE_ID');
$fp = fopen('/your_puth/filename.jpg', 'wb');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Google Drive API needs to be connected to the resource in step 1 - and not to yours
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question