[英]How to use google-api-ruby-client with the Google Calendar API?
[英]how to authorizate use google-api-ruby-client
我正在使用谷歌api的紅寶石,但不知道如何開始,只是給我一個ABC示例的人,非常感謝?
如果您要創建服務帳戶應用程序以訪問Google Analytics。
這里有一些代碼可以幫助您入門
require 'rubygems' require 'google/api_client' api_client = Google::APIClient.new path_to_key_file ="/path/to/key/file-privatekey.p12" passphrase = "google_generated_password" key = Google::APIClient::PKCS12.load_key(path_to_key_file, passphrase)
密鑰可用后,使用您的客戶端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_token
http://code.google.com/p/google-api-ruby-client/wiki/ServiceAccounts
我在其他一些帖子中回答了類似的問題,我發現它們就像這一個...因此,對於ruby,使用google-api-client(對於任何谷歌api),有一些ins使用api密鑰而不是OAuth時使用身份驗證進行...
我在代碼居住區概述了這個過程(使用api密鑰服務器端)。
在構造客戶端時,您必須將授權參數顯式設置為nil,否則gem會嘗試使用OAuth進行身份驗證,因此如果僅使用api密鑰從服務器調用,則始終會獲得401 Unauthorized。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.