0

我正在尝试使用 Ruby on Rails 应用程序创建/查看 Google Doc。我认为我可以创建文档,但是当我单击从 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

有什么建议么?

谢谢!

4

1 回答 1

1

如果您单击的链接是 ,downloadUrl那么这在浏览器中将不起作用。您应该webContentLink在浏览器中使用并登录 Google。

于 2013-02-03T16:36:22.070 回答