简体   繁体   English

如何使用Drive API的Ruby客户端将文本写入Google文档?

[英]How Do I Write Text to a Google Doc using Drive API's Ruby Client?

Hello SO Ruby/Rails/Google community! 您好Ruby / Rails / Google社区!

I'm looking for the correct way of making changes to the body of a Google Doc stored in Google Drive using Drive API Ruby Client. 我正在寻找使用Drive API Ruby Client更改存储在Google云端硬盘中的Google文档正文的正确方法。

Let's say I've required 'google/api_client' , have an authorized client and drive instance, and have a starting template written in HTML. 假设我需要'google/api_client' ,具有授权的客户端和驱动器实例,并且具有以HTML编写的启动模板。

I have no trouble creating fresh templates and multipart-uploading them to drive using 我毫不费力地创建了新模板并进行多部分上传以使用

@drive.files.insert

to join file metadata: 加入文件元数据:

@file = @drive.files.insert.request_schema.new({
            'title' => "#{Time.now.strftime('%m_%d_%Y_')}EOD",
            'description' => "The End of Day Log for #{Time.now.strftime('%m_%d_%Y')}",
            'mimeType' => 'text/html',
            'parents' => [{'id' => folder_id}]
        })

and the html template represented by: 和html模板,表示为:

@media = Google::APIClient::UploadIO.new('eod_template.html', 'text/html')

Having successfully uploaded the base template to Drive and capturing its file_id, I would like users to be able to append text entries to the base template using a form on my Rails site. 成功将基本模板上传到云端硬盘并捕获其file_id之后,我希望用户能够使用Rails网站上的表单将文本条目附加到基本模板上。

Given the existence of a micropost model and form, I suspect I'll be writing a method that get called on save that appends the submitted text to the Google Doc Template but I can't find how to do this in any of the Drive API documentation. 考虑到存在微博模型和表单,我怀疑我将编写一种在保存时调用的方法,该方法会将提交的文本追加到Google Doc模板中,但我无法在任何Drive API中找到方法文档。

I'm looking for functionality identical to the apps-script appendText(text) method found at https://developers.google.com/apps-script/reference/document/text 我正在寻找与https://developers.google.com/apps-script/reference/document/text中找到的apps-script appendText(text)方法相同的功能

Anyone have any clever solutions? 有人有什么聪明的解决方案吗? Documentation I should read? 我应该阅读的文档? The Perfect Gem? 完美的宝石?

Thanks a mil for your time! 感谢您的宝贵时间!

-B -B

I gather from the deafening silence that such a thing is not (easily) possible. 我从震耳欲聋的沉默中得知,这种事情不可能(轻松)。 Bummer! 坏消息! Not to be deterred, I implemented the following workaround - hope it works for you, future readers. 顺便说一下,我实施了以下解决方法-希望它对您(以后的读者)有用。 Instead of writing posts to a document dynamically, I let a day's worth of posts pool in my app until the end of day, at which point I write all posts to the Google Doc at once with Nokogiri. 我没有动态地将帖子写到文档中,而是将一天的帖子存储在应用程序中直到一天结束,这时,我用Nokogiri一次将所有帖子写到了Google文档中。 It's not great, but with some front-end trickery whereby I simulate the feel of a Google Doc, it's good enough. 它不是很好,但是通过一些前端技巧,我可以模仿Google Doc的感觉,这已经足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ruby:使用 google-api-ruby-client SDK 将文件上传到 Google Drive 失败并出现 Timeout::Error - Ruby : File upload to Google drive using google-api-ruby-client SDK failing with Timeout::Error 将 React 用作前端时,如何在 Ruby API 中访问用户的 Google 日历? - How do I get access User's Google Calendar in my Ruby API when using it with React as a Frontend? 如何使用 google drive ruby​​ gem 在驱动器文件夹中上传 google doc 文件或驱动器文件? - How to upload google doc file or drive file in drive folder with google drive ruby gem? 如何使用 ruby 中的 Google Drive api 获取 Google Drive 上文件夹内所有文件的列表 - How to get list of all files inside a folder on Google Drive using Google Drive api in ruby 如何使用ruby客户端访问包含siteURL的Google API方法? - How do I access Google API methods that include siteURL with the ruby client? 在 Ruby 中使用 Google Drive API - Use Google Drive API in Ruby 我如何通过google-api-ruby-client 0.9授权OAuth 2.0使用Google API服务? - How can I OAuth 2.0 authorise a Google API service with google-api-ruby-client 0.9? 如何授权 google-api-ruby-client? - How to authorize the google-api-ruby-client? 如何在Ruby中保存Google API凭据? - How do I save Google API credentials in Ruby? 如何在Ruby中使用matchdata对象编写条件逻辑? - How do I write conditional logic using a matchdata object in Ruby?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM