1

我像这样上传文件:

    if (isset($_FILES[$name])) {
        $service = new Google_DriveService($client);

        //Insert a file
        $file = new Google_DriveFile();
        $file->setTitle($_FILES[$name]['name']);
        $file->setMimeType($_FILES[$name]['type']);
        $file->setParents(array('imgs'));

        $insertedFile = $service->files->insert($file, array(
            'data' => file_get_contents($_FILES[$name]['tmp_name']),
            'mimeType' => $_FILES[$name]['type']
        ));

        return $insertedFile;
    }

得到insertedFile这样的:

Array
(
    [kind] => drive#file
    [id] => 1sASTlgG7IFzcZyTUihp53uJbppFtxLs_GK_V2jYwapE
    [etag] => "vGmlhiWxP02tugPmRvLynwC_A0Y/MTM2NjE4NTYyNzQwOQ"
    [selfLink] => https://www.googleapis.com/drive/v2/files/1sASTlgG7IFzcZyTUihp53uJbppFtxLs_GK_V2jYwapE
    [alternateLink] => ...

但是当我去 selfLink 时,我得到一个错误

{
  ...
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

在没有任何授权的情况下获取上传文件的正确方法是什么?看起来文件只能通过 API 获得。

4

1 回答 1

0

如果要下载内容,请向下载 URL 发出经过身份验证的请求。

// Get the contents of the file.
$request = new Google_HttpRequest($file->downloadUrl);
$response = $client->getIo()->authenticatedRequest($request);
$content = $response->getResponseBody();
于 2013-04-17T08:15:26.923 回答