简体   繁体   English

我正在尝试跳过“Google Drive 无法扫描此文件中的病毒”并直接生成下载链接

[英]I am trying to skip 'Google Drive can't scan this file for viruses' and directly generate the download link

The website stores a cookie with name = "download_warning_17554090818303548941_17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe" ('17554090818303548941' This part is different for every user.) and value = "dYTm" (This changes after every reload.)该网站存储一个 cookie,其名称 = "download_warning_17554090818303548941_17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe" ('17554090818303548941' 这部分因每个用户而异。) 和 value = "dYTm"(每次重新加载后都会更改。)

Once this cookie is present.一旦这个 cookie 出现。 Opening this https://drive.google.com/u/0/uc?export=download&confirm=IZu5&id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe will respond you with the download link.打开此https://drive.google.com/u/0/uc?export=download&confirm=IZu5&id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe将通过下载链接回复您。 I am think that using curl php would do it.我认为使用 curl php 可以做到。 I already have the cookie, but don't know how to use it to open the link mentioned above to get the correct response.我已经有了cookie,但不知道如何使用它来打开上面提到的链接以获得正确的响应。

$ch = curl_init('https://drive.google.com/uc?id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe&export=download');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  // get headers too with this line
  curl_setopt($ch, CURLOPT_HEADER, 1);
  $result = curl_exec($ch);
  preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
  $cookies = array();
  foreach($matches[1] as $item) {
      parse_str($item, $cookie);
      $cookies = array_merge($cookies, $cookie);
    }
var_dump($cookies);

I use this code to get the cookies.我使用此代码获取 cookies。 But don't know how to use it again so that it can be use to verify the confirm code and generate the download link.但是不知道如何再次使用它,以便可以使用它来验证确认码并生成下载链接。

I can explain the logic but i don't have time to code:我可以解释逻辑,但我没有时间编码:

When you first当你第一次

GET https://drive.google.com/u/0/uc?export=download&confirm=IZu5&id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe
                                                    ^^^^^^^^^^^^

You can see the response headers includes the cookie you were talking about ( download_warning_17554090818303548941_17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe={{VALUE}} )您可以看到响应标头包含您正在谈论的 cookie ( download_warning_17554090818303548941_17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe={{VALUE}} )

In order to verify and download the file, you need to GET again at the same address again, but you need to programmatically change the old confirm=IZu5 by confirm={{VALUE}}为了验证和下载文件,您需要再次在同一地址再次GET,但您需要通过confirm={{VALUE}}以编程方式更改旧的confirm=IZu5

GET https://drive.google.com/u/0/uc?export=download&confirm={{VALUE}}&id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe
                                                    ^^^^^^^^^^^^^^^^^

This will confirm the download and will trigger a few redirection (status 302) that will end up downloading your file这将确认下载并触发一些重定向(状态 302),最终将下载您的文件

在此处输入图像描述 This code give me the correct download link but I still can't download it.此代码为我提供了正确的下载链接,但我仍然无法下载。 Because access is denied.因为访问被拒绝。

<?php
  $url = "https://drive.google.com/uc?id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe&export=download";
  $handle = curl_init();
  curl_setopt($handle, CURLOPT_URL, $url);  
  curl_setopt($handle, CURLOPT_NOBODY, True);
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($handle, CURLOPT_HEADER, 1);
  $result = curl_exec($handle);
  preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
  $cookies = array();
  foreach($matches[1] as $item) {
      parse_str($item, $cookie);
      $cookies = array_merge($cookies, $cookie);
    }
    
    $keys = array_keys($cookies);
    $values = array_values($cookies);
    $next_url = "https://drive.google.com/uc?export=download&confirm=" . $values[0] . "&id=17_sIpX2amTqf2VOpLPO9IM9rDB-4vFHe";
    $res_cookie = "";
    for ($i=0; $i < sizeof($keys); $i++) { 
      $res_cookie .= $keys[$i];
      $res_cookie .= "=";
      $res_cookie .= $values[$i];
      if ($i < sizeof($keys) - 1) {
        $res_cookie .= "; ";
      }
    }
    curl_close($handle);
    // $verbose = fopen('php://temp', 'w+');
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, $next_url);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($handle, CURLOPT_COOKIE, $res_cookie);
    curl_setopt($handle, CURLOPT_HEADER, 1);
    curl_setopt($handle, CURLOPT_VERBOSE, true);
    // curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
    // curl_setopt($handle, CURLOPT_STDERR, $verbose);

    $result = curl_exec($handle);
    echo $result;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生成Google驱动器链接的自定义直接下载链接 - generate custom direct download link for google drive link 尝试从Google云端硬盘下载文件,但downloadUrl不随元数据一起提供 - Trying to download a file from Google Drive, but the downloadUrl isn't coming with the metadata 我可以使用Drive API从Google Spreadsheet下载数据吗? - Am I able to download the data from a Google Spreadsheet with the Drive API? 我正在尝试生成.sql转储文件并使用php自动下载 - I am trying to to generate a .sql dump file and auto-download using php Google Drive直接(原始)链接下载图像文件 - Google drive direct(raw) link to download image file 我正在尝试从mysql下载文件,我将文件位置保存在数据库中,现在我正在尝试为页面上的用户创建下载链接 - I am trying to download a file from mysql, I saved the file location in the database, now I am trying to make a download link for the user on my page 试图生成一个PHP下载链接。 不会设置文件名 - Trying to generate a php download link. Name of file will not set 如何从带有 php 的谷歌驱动器文件中下载 url? - How can I get download url from a file of google drive with php? 从数据库中选择文件时,不会生成下载链接 - Download link doesn't generate when I select a file from database 无法更新Google云端硬盘文件 - Can't update Google Drive file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM