我正在尝试编写一个命令,该命令将使用其可共享链接读取在谷歌驱动器上上传的文本文件。我正在使用symfony2。 这是我的代码。
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$queryFile = 'https://drive.google.com/open?id=0B6NZHCoBtjaLZXRmWG5JQWhLWEU'
try {
$client = new Client();
$cloudFile = "temp/query";
$request = $client->get($queryFile, ['save_to'=>$cloudFile]);
$fileName = $cloudFile;
$file = fopen($fileName, 'r');
$queryStatement = fread($file, filesize($fileName));
$output->writeln($queryStatement);
if (!$file) {
$output->writeln('<error> Cannot open the file </error>');
return;
}
} catch (RequestException $e) {
$output->writeln('Fetching cloud file failed');
}
可共享的链接是
https://drive.google.com/open?id=0B6NZHCoBtjaLZXRmWG5JQWhLWEU
但这是我得到的结果。
<!DOCTYPE html><html><head><meta name="google" content="notranslate"><meta http-equiv="X-UA-Compatible" content="IE=edge;"><meta name="fragment" content="!"><title>query - Google Drive</title><meta property="og:title" content="query"><meta property="og:type" content="article"><meta property="og:site_name" content="Google Docs"><meta property="og:url" content="https://drive.google.com/file/d/0B6NZHCoBtjaLZXRmWG5JQWhLWEU/view?usp=sharing&usp=embed_facebook"><meta name="twitter:card" content="photo"><meta name="twitter:title" content="query"><meta name="twitter:url" content="https://drive.google.com/file/d/0B6NZHCoBtjaLZXRmWG5JQWhLWEU/view?usp=sharing&usp=embed_twitter"><meta name="twitter:site" content="@googledocs"><script>(function(){(function(){function e(a){this.t={};this.tick=function(a,c,b){var d=void 0!=b?b:(new Date).getTime();this.t[a]=[d,c];if(void 0==b)try{window.console.timeStamp("CSI/"+a)}catch(e){}};this.tick("start",null,a)}var a;window.performance&&(a=window.performance.timing);var f=a?new e(a.responseStart):new e;window.jstiming={Timer:e,load:f};if(a){var c=a.navigationStart,d=a.responseStart;0<c&&d>=c&&(window.jstiming.srt=d-c)}if(a){var b=window.jstiming.load;0<c&&d>=c&&(b.tick("_wtsrt",void 0,c),b.tick("wtsrt_",