Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Google Drive上的服务帐户需要登录_Ruby On Rails_Ruby_Google Drive Api_Google Api Ruby Client - Fatal编程技术网

Ruby on rails Google Drive上的服务帐户需要登录

Ruby on rails Google Drive上的服务帐户需要登录,ruby-on-rails,ruby,google-drive-api,google-api-ruby-client,Ruby On Rails,Ruby,Google Drive Api,Google Api Ruby Client,我正在尝试使用RubyonRails应用程序创建/查看Google文档。我认为我能够创建文档,但是当我单击从API回调中获得的链接时,我得到一个错误401:需要登录 下面是我用来创建文档的代码 key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'notasecret') asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EM

我正在尝试使用RubyonRails应用程序创建/查看Google文档。我认为我能够创建文档,但是当我单击从API回调中获得的链接时,我得到一个错误401:需要登录

下面是我用来创建文档的代码

key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'notasecret')
asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL,
    'https://www.googleapis.com/auth/drive', key)
client = Google::APIClient.new
client.authorization = asserter.authorize()
drive = client.discovered_api('drive', 'v2')
puts 'hello'
file = drive.files.insert.request_schema.new({
  'title' => 'My document',
  'description' => 'A test document',
  'mimeType' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
})
puts 'world'
media = Google::APIClient::UploadIO.new(Rails.root.to_s + '/app/assets/documents/document.doc', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
result = client.execute(
  :api_method => drive.files.insert,
  :body_object => file,
  :media => media,
  :parameters => {
  'uploadType' => 'multipart',
  'alt' => 'json'}
)

puts '==========='
puts result
puts '==========='
jj result.data.to_hash
有什么建议吗


谢谢

如果您正在单击的链接是
下载URL
,则这在浏览器中不起作用。你应该在浏览器中使用
webContentLink
,然后登录到谷歌。

这里有一个谷歌硬盘gem,从我这里看到的似乎更容易使用。有没有一种方法可以使用这个gem获得指向谷歌文档的链接?是的,想一想,就是这样:我在用它制作电子表格,很简单。谢谢!你真棒。这个宝石真的很好用!