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

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

问题描述

我希望使用 Google云端硬盘API 来创建新的Google幻灯片,但其中一张幻灯片是从另一张以前的演示文稿中复制的.

I wish to use Google Drive API for creating a new Google Slides, but with one slide copied from another previous presentation.

我的问题是,是否可以构建一个新的Google幻灯片并将幻灯片(单)插入到新幻灯片中.

My question is, is that possible to build a new Google Slides and insert slides (singularly) into the new one.

还是可以从Google Presentation中删除幻灯片?

Or is it possible to delete the a slide from Google Presentation?

推荐答案

(2017年2月)截至2016年11月,使用 Google云端硬盘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).

听起来像您正在使用用于Ruby的Google API客户端库 ,因此您已在那里.下一步是使用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快速入门示例,这是 Slides API的Ruby快速入门.如果您不对Python过敏(如果是的话,就假装它是伪代码;)),那么我已经使

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.

下面是另一个Python示例,您可以移植到Ruby,它完全按照OP的要求进行操作,假设您的模板文件是SLIDE_TEMPLATE_FILEDRIVE是您的Drive API服务端点,而SLIDES是该API的端点幻灯片API.如果有人PMS给我一个Ruby端口,我将使用它来更新此答案.

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

最后,是的,您还可以使用

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幻灯片复制到新的演示文稿中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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