5

I'm using Google Drive API (v3) with Google's PHP api client to list and display videos from my Drive, where I'm also displaying thumbnails for said videos. I have difficulties getting thumbnail urls back from the API, although I enabled thumbnailLink in request parameters:

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

Value for thumbnailLink is still empty, other values are returned successfully. I looked for thumbnail settings in api documentation, without success. API also doesn't return any error. What could it be?

Here's the code I'm using:

$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();

and var_dump of response

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) {
}
}...
boogysi
  • 51
  • 5
  • There are multiple questions here which makes your posting too overly-broad. Refer to [ask]. You also didn't even bother to take the 2-minute site [tour]. – T-Heron Dec 28 '16 at 13:09
  • I've revised the question and removed secondary questions. – boogysi Dec 28 '16 at 14:11

3 Answers3

2

Try to double check if you properly use a correct scope. I suggest you to use the https://www.googleapis.com/auth/drive for full permissive scope to access all of a user's files. If it's still not working, then try the suggested solution here.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31
0

Try items.thumbnailLink

This is what the response from the Drive API looks like.

{
 "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
   },...

Hope this helps!

Elon Zito
  • 2,872
  • 1
  • 24
  • 28
  • Hi Elon, thank you for replying. I guess this must have worked in v2, but it doesn't seem to in v3. I updated my initial question with the request code I'm using and the response, where `thumbnailLink` is still ignored (returns `null`). – boogysi Dec 28 '16 at 14:10
0

I know you're trying to get a list of files, and this only retrieves a link from one, but this would have helped me a lot, and I think it's similar enough in concept to be potentially helpful to others:

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;
}

I am still interested in whether you were able to get thumbnail links for multiple files using getFiles().

jbobbins
  • 1,221
  • 3
  • 15
  • 28