将使用API​​的Google演示文稿中的一张幻灯片复制到新的Google演示文稿中 [英] Copy one slide from google presentation into a new google presentation using API

查看:145
本文介绍了将使用API​​的Google演示文稿中的一张幻灯片复制到新的Google演示文稿中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 Google驱动器api 创建新的Google演示文稿,但要与从另一个以前的Google演示文稿中复制了一张幻灯片。

I wish to use Google drive api for creating a new Google Presentation but with one slide copied from another previous google presentation.

我的问题是,是否可以构建新的Google演示文稿并将幻灯片(单独)插入新演示文稿。
或者是否可以从Google演示文稿中删除一张幻灯片?

My question is, Is that possible to build a new Google Presentation and insert slides(singularly) into the new one. Or is it possible to delete the a slide from Google Presentation ?

推荐答案

(2017年2月)截至2016年11月,发布 Google幻灯片API ,现在可以选择OP所要求的解决方案,尽管不是直接与API。该解决方法是您要复制的一张幻灯片位于其自己的独立文件中。然后,您可以使用两个 Google API来实现它:幻灯片API(用于执行文档级别的功能,如添加新幻灯片)以及 Google Drive API (用于文件的复制等面向访问)。

(Feb 2017) As of Nov 2016 with the release of the Google Slides API, an alternative to the solution the OP is asking for is now possible although not directly with the API. That workaround is that the ONE SLIDE you want copied is in its own standalone file. Then you can use two Google APIs to make it happen: the Slides API (to perform the document-level functions like adding new slides) as well as the Google Drive API (for file-oriented access like copying).

听起来就像您使用 Google API客户端库对于Ruby ,所以你就在那里设置。下一步是使用Google云端硬盘和Google幻灯片API在 Google Developers Console 中创建一个项目,然后在创建OAuth2凭证后下载 client_secret * .json 文件。

Sounds like you're using the Google APIs Client Library for Ruby, so you're set there. The next step is to create a project in the Google Developers Console with both the Google Drive and Google Slides APIs enabled, then download the client_secret*.json file after you create your OAuth2 credentials.

为了帮助您开始使用,这里是适用于Drive API的 Ruby快速入门示例,以下是为幻灯片API Ruby快速入门。如果你对Python没有过敏(如果你是,只是假装它是伪代码;)),我已经制作了多个视频,并提供更多真实世界的示例,使用可以学习并迁移到Ruby的幻灯片API。

To help you get started, here's the Ruby quickstart sample for the Drive API, and here's the Ruby quickstart for the Slides API. If you're not "allergic" to Python (if you are, just pretend it's pseudocode ;) ), I've made several videos with more "real-world" examples of using the Slides API you can learn from and migrate to Ruby if desired.

以下是另一个可以移植到Ruby的Python示例,该示例假定您的模板文件是 SLIDE_TEMPLATE_FILE DRIVE 是您的Drive API服务端点,而 SLIDES 是幻灯片API的端点。

Below is another Python example which you can port to Ruby that does exactly what the OP asked, assuming your template file is SLIDE_TEMPLATE_FILE, DRIVE is your Drive API service endpoint, and SLIDES is the endpoint for the Slides API. If someone PMs me a Ruby port, I'll update this answer with it.

# query for template file with one slide
TMPLFILE = SLIDE_TEMPLATE_FILE
rsp = DRIVE.files().list(q="name='%s'" % TMPLFILE).execute().get('files')[0]

# copy template file
DATA = {'name': 'Google Drive & Slides API template DEMO'}
DECK_ID = DRIVE.files().copy(body=DATA, fileId=rsp['id']).execute().get('id')

# create 2 more (1 title-only & 1 blank) slides in copied file
reqs = [
    {'createSlide': {'slideLayoutReference': {'predefinedLayout': 'TITLE_ONLY'}}},
    {'createSlide': {'slideLayoutReference': {'predefinedLayout': 'BLANK'}}},
]
SLIDES.presentations().batchUpdate(body={'requests': reqs},
        presentationId=DECK_ID).execute()

,您还可以使用 deleteObject请求

Finally, yes, you can also delete slides from presentations with the deleteObject request, passing in the ID of the slide/page you want removed. Another workaround if you can't isolate the ONE SLIDE: copy the entire presentation & delete all pages except the ONE SLIDE, then start adding new slides. Hopefully the API will eventually get "the right solution" so we don't have to play these games.

这篇关于将使用API​​的Google演示文稿中的一张幻灯片复制到新的Google演示文稿中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆