[英]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.