Google APIClient - 无效的密钥文件或密码

Google APIClient - Invalid keyfile or passphrase

我正在尝试将一些功能从 Sinatra 应用程序移植到 Rails 应用程序。在 Sinatra 应用程序中,代码运行良好。当我将代码带入 Rails 时,它失败了。我怀疑这是我传递 config.pk 文件的方式,但几个小时后我仍然不知道。如何成功从KeyUtils获取密钥?

$ cd path/to/app
app $ rails c
Loading development environment (Rails 4.2.0.rc2)
2.1.2 :001 > key_file_path = Rails.root.join('config.p12').to_s
2.1.2 :002 > key_file = File.read(key_file_path)
2.1.2 :003 > passphrase = 'notasecret'
2.1.2 :004 > require 'google/api_client'
2.1.2 :005 > key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file, passphrase)
ArgumentError: Invalid keyfile or passphrase
2.1.2 :006 > key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file_path, passphrase)
ArgumentError: Invalid keyfile or passphrase
2.1.2 :007 > key_file.length
 => 4330
2.1.2 :008 > key_file
 => "3082 06c0 0201 0330 8206 7a06 092a 8648\n86f7 0d01 0701 a082 066b 0482 0667 3082\n0663 3082 0328 0609 2a86 4886 f70d 0107\n01a0 8203 1904 8203 1530 8203 1130 8203\n0d06 0b2a 8648 86f7 0d01 0c0a 0102 a082\n02b2 3082 02ae 3028 060a 2a86 4886 f70d\n010c 0103 301a 0414 a6bd 5765 7b62 fcbd\ncccf 4e26 [... key file abbreviated ...] 5270\n0202 0400 "

文件夹结构

my_rails_root_folder

|_ config.p12

我也在尝试遵循此 Google 文档: https://github.com/tpitale/legato/wiki/OAuth2-and-Google#application-code

提前致谢。

纠结了半天,我把原文档复制了一份,放到了新的app里。然后一切又开始工作了。

之前,我复制了证书的内容,而不是文件本身。显然这还不够好,我不得不复制整个文件。