首页 > 解决方案 > 如何指定谷歌幻灯片 API PNG 导出的图像大小?

问题描述

我能够成功运行下面的代码来生成一个带有我的谷歌幻灯片图像的 URL,但是当我尝试指定 thumbnailProperties 时,它说:“得到了一个意外的关键字参数“thumbnailProperties””。我遵循了这个文档:https ://developers.google.com/slides/api/reference/rest/v1/presentations.pages/getThumbnail?hl=es

关于我需要改变什么的任何想法?

service = build('slides', 'v1', credentials=creds)

img = service.presentations().pages().getThumbnail(
        presentationId=PRESENTATION_ID, 
        pageObjectId='gd7f6eed13a_1_17',
        # thumbnailProperties = {'thumbnailSize': 'LARGE'}
        ).execute()

标签: pythongoogle-slides-api

解决方案


在这种情况下,请进行如下修改。

修改后的脚本:

service = build('slides', 'v1', credentials=creds)

img = service.presentations().pages().getThumbnail(
        presentationId=PRESENTATION_ID, 
        pageObjectId='gd7f6eed13a_1_17',
        thumbnailProperties_thumbnailSize='LARGE' # Modified
        ).execute()

由此,得到以下结果。当您要检索缩略图图像时,请从以下下载contentUrl。在这种情况下,不需要使用访问令牌。

{
  'height': 900,
  'width': 1600,
  'contentUrl': 'https://lh3.googleusercontent.com/###=s1600'
}

参考:


推荐阅读