2014-10-27 36 views
1

嗨我是深夜黑客和測試谷歌api客戶端的Ruby。不能冒充服務到服務oauth請求到紅寶石日曆api

我可能因誤會而陷入錯誤。

我已經做了

  • 我已經創造了谷歌開發者控制檯
  • 的應用程序,我啓用了日曆API
  • 我創建的服務器密鑰和下載的P12。
  • 我設法看到使用谷歌API的瀏覽器和瀏覽器的OAuth該日曆的元數據,所以ID被確認和權限也爲瀏覽器的OAuth可以查看元數據

什麼我triying做:

我正在試圖從一個私人共享的日曆中獲取元數據(我通過一個谷歌應用程序的Google應用程序中的讀取權限(槽組))在服務上驗證服務的驗證

如何我triying做

有了這個代碼:

require 'google/api_client' 
require 'pp' 
client = Google::APIClient.new 

cal = client.discovered_api('calendar','v3') 

id = '[email protected]' # id is the confirmed calendar ID 

key = Google::APIClient::KeyUtils.load_from_pkcs12('sl.p12', 'notasecret') 
client.authorization = Signet::OAuth2::Client.new(
    :token_credential_uri => 'https://accounts.google.com/o/oauth2/token', 
    :audience => 'https://accounts.google.com/o/oauth2/token', 
    :scope => 'https://www.googleapis.com/auth/calendar', 
    :issuer => '[email protected]', # confirmed issuer 

    :signing_key => key 
) 

client.authorization.fetch_access_token! 

result = client.execute(
    :api_method => cal.calendars.get, 
    :parameters => { 'calendarId' => id } 
) 

puts result.response.body 

pp result 

結果colected

當我這樣做Ÿ得到404,像「該日曆不存在」

{ 
    "error": { 
    "errors": [ 
     { 
     "domain": "global", 
     "reason": "notFound", 
     "message": "Not Found" 
     } 
    ], 
    "code": 404, 
    "message": "Not Found" 
    } 
} 

但是,如果我每 '初級'

更改ID,我得到:

{ 
"kind": "calendar#calendar", 
"etag": "\"dAAhx6wYoPw2vqRAe54lk5wa0XQ/WEglF6_c5pVHKyggcENvvX1cS9g\"", 
"id": "[email protected]", #same as issuer id ??? WTF 
"summary": "[email protected]om", 
"timeZone": "UTC" 
} 

這似乎是一個日曆,但它像出現在服務器密鑰的「電子郵件發行人」賬戶的默認日曆「電子郵件」字段

我也試過廣告:person = 'email'client.authorization但然後我創建身份驗證令牌時出現錯誤

我無法找到一種方式來訪問該API作爲其他郵件帳戶不同於@ developer.gserviceaccount.com,所以我做錯了什麼?

回答

1

您可以共享與服務帳戶的電子郵件日曆或者按照these steps允許服務帳戶來假冒該域中任何用戶,在這種情況下,你必須通過:person => 'email'參數。