V
V
valentin_dev2022-01-12 15:53:49
PHP
valentin_dev, 2022-01-12 15:53:49

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

3 answer(s)
V
valentin_dev, 2022-01-12
@valentin_dev

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);

Thanks everyone, issue resolved.

A
Anton, 2022-01-12
@karminski

Google Drive API needs to be connected to the resource in step 1 - and not to yours

V
Vitaliy K, 2022-01-13
@revenger

Downloading large files from google drive via com...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question