Google Drive API缩略图参数

时间:2016-12-28 13:04:58

标签: php google-drive-api thumbnails video-thumbnails

我正在使用Google Drive API(v3)与Google的PHP api客户端列出并显示来自我的云端硬盘的视频,其中我还显示了所述视频的缩略图。虽然我在请求参数中启用了thumbnailLink,但我很难从API中获取缩略图网址:

'fields' => 'nextPageToken, files(id, name, thumbnailLink, webContentLink, webViewLink)'

thumbnailLink的值仍为空,其他值成功返回。我在api文档中查找缩略图设置,但没有成功。 API也不会返回任何错误。它可能是什么?

这是我正在使用的代码:

$drive_service = new Google_Service_Drive($client);

$optParams = array(
'pageSize' => 4,
'q' => "'0B_nSMgQioOWwNy1ha0tFWEE0QWs' in parents and mimeType contains 'video/'",
'fields' => 'nextPageToken, files(id, name, modifiedTime, mimeType, createdTime, thumbnailLink, webContentLink, webViewLink)'
);

return $files_list = $drive_service->files->listFiles($optParams)->getFiles();

和响应的var_dump

array(4) {
[0]=>
object(Google_Service_Drive_DriveFile)#590 (56) {
["collection_key":protected]=>
string(6) "spaces"
["appProperties"]=>
NULL
["capabilitiesType":protected]=>
string(42) "Google_Service_Drive_DriveFileCapabilities"
["capabilitiesDataType":protected]=>
string(0) ""
["contentHintsType":protected]=>
string(42) "Google_Service_Drive_DriveFileContentHints"
["contentHintsDataType":protected]=>
string(0) ""
["createdTime"]=>
string(24) "2016-09-12T19:54:22.000Z"
["description"]=>
NULL
["explicitlyTrashed"]=>
NULL
["fileExtension"]=>
NULL
["folderColorRgb"]=>
NULL
["fullFileExtension"]=>
NULL
["headRevisionId"]=>
NULL
["iconLink"]=>
NULL
["id"]=>
string(35) "1St7nQ3X3-ocrMUC2t-r6NOVc4xIdfhbIgg"
["imageMediaMetadataType":protected]=>
string(48) "Google_Service_Drive_DriveFileImageMediaMetadata"
["imageMediaMetadataDataType":protected]=>
string(0) ""
["isAppAuthorized"]=>
NULL
["kind"]=>
NULL
["lastModifyingUserType":protected]=>
string(25) "Google_Service_Drive_User"
["lastModifyingUserDataType":protected]=>
string(0) ""
["md5Checksum"]=>
NULL
["mimeType"]=>
string(9) "video/mp4"
["modifiedByMeTime"]=>
NULL
["modifiedTime"]=>
string(24) "2016-12-27T11:55:43.958Z"
["name"]=>
string(12) "MOV_1950.mp4"
["originalFilename"]=>
NULL
["ownedByMe"]=>
NULL
["ownersType":protected]=>
string(25) "Google_Service_Drive_User"
["ownersDataType":protected]=>
string(5) "array"
["parents"]=>
NULL
["permissionsType":protected]=>
string(31) "Google_Service_Drive_Permission"
["permissionsDataType":protected]=>
string(5) "array"
["properties"]=>
NULL
["quotaBytesUsed"]=>
NULL
["shared"]=>
NULL
["sharedWithMeTime"]=>
NULL
["sharingUserType":protected]=>
string(25) "Google_Service_Drive_User"
["sharingUserDataType":protected]=>
string(0) ""
["size"]=>
NULL
["spaces"]=>
NULL
["starred"]=>
NULL
["thumbnailLink"]=>
NULL
["trashed"]=>
NULL
["version"]=>
NULL
["videoMediaMetadataType":protected]=>
string(48) "Google_Service_Drive_DriveFileVideoMediaMetadata"
["videoMediaMetadataDataType":protected]=>
string(0) ""
["viewedByMe"]=>
NULL
["viewedByMeTime"]=>
NULL
["viewersCanCopyContent"]=>
NULL
["webContentLink"]=>
string(82) "https://drive.google.com/uc?id=1St7nQ3X3-ocrMUC2t-r6NOVc4xIdfhbIgg&export=download"
["webViewLink"]=>
string(85) "https://drive.google.com/file/d/1St7nQ3X3-ocrMUC2t-r6NOVc4xIdfhbIgg/view?usp=drivesdk"
["writersCanShare"]=>
NULL
["internal_gapi_mappings":protected]=>
array(0) {
}
["modelData":protected]=>
array(0) {
}
["processed":protected]=>
array(0) {
}
}...

3 个答案:

答案 0 :(得分:1)

尝试仔细检查您是否正确使用了正确的范围。我建议您使用https://www.googleapis.com/auth/drive获取完全许可范围来访问所有用户的文件。如果它仍然不起作用,请尝试建议的解决方案here

答案 1 :(得分:0)

尝试{ "kind": "drive#fileList", "etag": "\"m64ksZC09nG4-fB1IRF3vg/1C1ON4SO5V-To1u55k7dU\"", "selfLink": "https://www.googleapis.com/drive/v2/files?corpus=DEFAULT", "nextPageToken": "V1*3|0|ChwwQjdXTWpmWkhhWHllTW1ObtQq", "nextLink": "https://www.googleapis.com/drive/v2/files?corpus=DEFAULT&pageToken=V1*3%7C0%7CChwwQjdVUnFTR05mZGpREgcQsonGqtQq", "items": [ { "kind": "drive#file", "id": "1DpsZKiII1pOsHxDrJDzBb_aW841Ovhm8pE5FCI", "etag": "\"m64ksZC09nG4-fB1IRF3vg/1C1ON4SO5V-To1u55k7dU\"", "selfLink": "https://www.googleapis.com/drive/v2/files/1DpsZKiII1pOsHbrEzvxDrJDzBb_aW841Ovhm8pE5FCI"... }, "defaultOpenWithLink": "https://docs.google.com/spreadsheets/d/1DpsZKihm8pE5FCI/edit?usp=drivesdk", "iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_11_spreadsheet_list.png", "thumbnailLink": "https://docs.google.com/feeds/vt?gd=true&id=1DpsZKiInoAAAAAWGPVboChWb270pOAY0M5hMr3FNa-IX6G&sz=s220", "title": "Document Title", "mimeType": "application/vnd.google-apps.spreadsheet", "labels": { "starred": false, "hidden": false, "trashed": false, "restricted": false, "viewed": true },...

这就是Drive API的响应。

$("#form-id").on('submit',(function(e) {
    e.preventDefault();
    $.ajax({
        url: "file-to-call.php",
        type: "POST",
        data: new FormData(this),
        cache: false,
        processData: false,
        success: function(data) {
            //handle success
        }
   });
}));

希望这有帮助!

答案 2 :(得分:0)

我知道你正在尝试获取一个文件列表,这只会从一个文件中检索一个链接,但这对我有很大帮助,而且我认为它在概念上足够类似,可能对其他人有所帮助: / p>

function getThumbnailUrl($fileId)
{
    $service = new Google_Service_Drive($this->client());
    $params = array('fields' => 'hasThumbnail, thumbnailLink');
    $file = $service->files->get($fileId, $params);
    $url = $file->getThumbnailLink();

    return $url;
}

我仍然对您是否能够使用getFiles()获取多个文件的缩略图链接感兴趣。