【发布时间】:2018-03-13 10:13:43
【问题描述】:
<?php
$id = '0B475ByfcR9n4a1JMVEZxQno2Tmc';
$ch = curl_init('https://drive.google.com/uc?id='.$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'));
$result = curl_exec($ch);
$object = json_decode(str_replace(')]}\'', '', $result));
exit(header('Location: '. $object->downloadUrl));
我曾尝试生成 google drive 直接下载链接,但未使用此代码成功打开网页,但今天无法正常工作:
【问题讨论】:
-
当我复制/粘贴你的代码时,我得到一个
400 Bad Request。 -
400 Bad Request表示未提供必填字段或参数,提供的值无效,或提供的字段组合无效。 Drive 还支持通过webViewLink属性中的 URL 让用户直接访问文件。您可以查看此链接作为参考:stackoverflow.com/questions/47625214/….
标签: php google-drive-api