使用API​​将一张幻灯片从Google幻灯片复制到新的演示文稿中

编程入门 行业动态 更新时间:2024-10-09 19:15:31
本文介绍了使用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 Slides API ,可以替代OP要求的解决方案,尽管该API不能直接使用.解决方法是,要复制的一张幻灯片位于其自己的独立文件中.然后,您可以使用两个 Google API来实现:幻灯片API(用于执行文档级功能,例如添加新幻灯片)以及 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过敏(如果是的话,就假装它是伪代码;)),那么我已经使几个视频,其中包含更多有关使用Slides API的真实世界"示例,您可以从中学习并迁移到Ruby.

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_FILE,DRIVE是您的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()

最后,是的,您还可以使用 deleteObject请求,传入您要删除的幻灯片/页面的ID.如果您无法隔离一张幻灯片,则可以采用另一种解决方法:复制整个演示文稿,删除除一张幻灯片以外的所有页面,然后开始添加新幻灯片.希望该API最终将获得正确的解决方案",这样我们就不必玩这些游戏了.

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幻灯片复制到新的演示文稿中

本文发布于:2023-10-31 10:14:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   到新   演示文稿   API   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!