最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google drive API get thumbnail - Stack Overflow

programmeradmin3浏览0评论

I want to get a thumbnail that google drive creates for the stored pdf files. With this function I am listing all the files:

  listFiles: function (folderId, onData, onError) {

    drive.files.list({
        auth: jwtClient,
        q: "'" + folderId + "' in parents"
    }, function (err, res) {
         console.log(res.files)
       }
    });

The output of a console log for each file looks like this:

{ 
  kind: 'drive#file',
  id: '0BapkdhpPsqtgf01YbEJRRlhuaVUf',
  name: 'file-name.pdf',
  mimeType: 'application/pdf' 
}

When I check the google's documentation, it says that metadata of a file should contain all of these properties: and there I found: contentHints.thumbnail.image How do I access it?

I want to get a thumbnail that google drive creates for the stored pdf files. With this function I am listing all the files:

  listFiles: function (folderId, onData, onError) {

    drive.files.list({
        auth: jwtClient,
        q: "'" + folderId + "' in parents"
    }, function (err, res) {
         console.log(res.files)
       }
    });

The output of a console log for each file looks like this:

{ 
  kind: 'drive#file',
  id: '0BapkdhpPsqtgf01YbEJRRlhuaVUf',
  name: 'file-name.pdf',
  mimeType: 'application/pdf' 
}

When I check the google's documentation, it says that metadata of a file should contain all of these properties: https://developers.google./drive/v3/reference/files and there I found: contentHints.thumbnail.image How do I access it?

Share Improve this question asked Jul 10, 2017 at 13:38 mirtamirta 67812 silver badges26 bronze badges 2
  • 2 Possible duplicate of Revisions list and get missing information – pinoyyid Commented Jul 10, 2017 at 15:40
  • 1 see stackoverflow./questions/44958371/… – pinoyyid Commented Jul 10, 2017 at 15:40
Add a ment  | 

3 Answers 3

Reset to default 8

You can use the fields parameter to change which metadata fields are returned:

drive.files.list({
    auth: jwtClient,
    q: "'" + folderId + "' in parents",
    fields: "files(id, name, mimeType, thumbnailLink)"
}, function (err, res) {
    console.log(res.files)
});

Ok, the thing is to get the metadata of a file I needed to use a files.get function, not files.list. Another thing is that in the call, field parameter needs to be set. For example:

drive.files.get({
    auth: jwtClient,
    fileId: fileId,
    fields : "thumbnailLink"
})

You can get essential metadata with following api call. Workaround for python:

self.__results = drive_service.files().list(pageSize=10, supportsAllDrives = True, fields = "files(kind, id, name, mimeType, webViewLink, hasThumbnail, thumbnailLink, createdTime, modifiedTime, owners, permissions, iconLink, imageMediaMetadata)").execute()

or

self.__results = drive_service.files().list(pageSize=10, supportsAllDrives = True, fields = "*").execute()

to get plete metadata.

Reference: https://developers.google./drive/api/v3/reference/files#resource

发布评论

评论列表(0)

  1. 暂无评论