【发布时间】:2017-12-09 18:09:56
【问题描述】:
尝试从 Google Drive API 获取图片 URL 而不是文件内容。 在新版本中,这个 GOOD 的东西已被弃用。
我搜索了很多,在谷歌开发者类上有一个方法,但是在新版本中也没有。
问题是我要从云端硬盘中获取大量图片,但又不想降低 Google 尝试通过我的应用浏览所有图片的速度。这也很愚蠢。
有没有办法以某种方式获取这些链接?
这是我用来获取文件内容的代码:
$this->client = new \Google_Client();
$this->client->setAuthConfigFile('config.json');
$this->client->setScopes('https://www.googleapis.com/auth/drive');
if (isset($_GET['code'])) $code = $_GET['code'];
if(!isset($_SESSION['access_token'])){
if (!isset( $code )){
$auth_url = $this->client->createAuthUrl();
$filtered_url = filter_var($auth_url, FILTER_SANITIZE_URL);
return redirect($filtered_url);
}else{
$this->client->authenticate($_GET['code']);
$_SESSION['access_token'] = $this->client->getAccessToken();
// return redirect('/');
}
}
$this->service = new \Google_Service_Drive($this->client);
$file_id = '0B3vR4cBcxn4oNm9TSlBzcngyMzQ';
$results = $this->service->files->get($file_id, array('alt' => 'media'));
$imaga = $results->getBody()->getContents();
$imageData = base64_encode($imaga);
$contentType = $results->getHeader("content-type");
$src = 'data: '.$contentType[0].';base64,'.$imageData;
【问题讨论】:
标签: php html node.js google-drive-api