generate custom direct download link for google drive link

I want to generate google drive direct download link without opening web page.

I have found 1 site which do same thing but I did not find how he is doing.

below is the site which generates direct download link without opening google drive page.

0B475ByfcR9n4a1JMVEZxQno2Tmc is google file and replace with any file.

can anyone tell me how can I do that?I want to make same page like above site.

I tried this url but its not working. instead of starting download it opens page.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

A quick look at the source of the site, it generates the following javascript.

    setTimeout(function() {
        window.location.href = "*/0B475ByfcR9n4a1JMVEZxQno2Tmc?e=download";
    }, 300);

But where does that url come from?

With a little fiddling and watching the console on when it does ask to confirm on google, you can see it does a POST request and returns some json.


So just mock that with PHP

Make a json POST request to that url, google will respond with the json, then just strip out )]}' json decode it, then use a header to redirect to the file.

$id = '0B475ByfcR9n4a1JMVEZxQno2Tmc';

$ch = curl_init(''.$id.'&export=download');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, []);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    ... see notice below
$result = curl_exec($ch);

$object = json_decode(str_replace(')]}\'', '', $result));

exit(header('Location: '. $object->downloadUrl));

Edit (08-04-18)

Looks like some additional headers have been added, if missing it will throw a 400 Bad Request. No biggie, it’s still easy to mock it by looking at the request headers when downloading a file from your own drive. I’m unwilling to share a copy&paste solution, as the above still works you just need to add some headers and StackOverflow is not a free coding service nor am I required to maintain every answer I’ve ever written. Good luck.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply