我正在使用ruby的google api,但不知道如何开始,给我一个ABC的例子,非常感谢?
发布于 2012-06-22 01:42:50
如果您正在创建服务帐户应用程序以访问Google Analytics。
需要'rubygems‘需要'google/ api_client’api_client= Google::APIClient.new path_to_key_file =“/path/to/ key /file-Priatekey.p12”passphrase = "google_generated_password“key=rubygems)
密钥可用后,使用您的客户端ID (API控制台中的电子邮件)和授权范围初始化断言程序。
asserter = Google::APIClient::JWTAsserter.new(
'super_long_client_id_from_api_console@developer.gserviceaccount.com',
'https://www.googleapis.com/auth/analytics.readonly',
key)
# To request an access token, call authorize:
api_client.authorization = asserter.authorize()
puts api_client.authorization.access_tokenhttp://code.google.com/p/google-api-ruby-client/wiki/ServiceAccounts
发布于 2012-07-14 17:44:49
我已经在我发现的其他几个帖子中回答了类似的问题,就像这篇文章一样……因此,对于ruby,使用google- api -client (对于任何google api),在使用api密钥而不是OAuth时,有一些与身份验证相关的问题……
我已经在the code abode概述了这个过程(使用api key服务器端)。
您必须在构建客户端时将授权参数显式设置为nil,否则gem将尝试使用OAuth进行身份验证,因此如果仅使用API键从服务器调用,您将始终得到401Uncredified。
the code abode - google-api-client for ruby
https://stackoverflow.com/questions/7493499
复制相似问题