1
在嘗試使用Legato gem和service accounts時,我們收到來自Google代碼Authorization failed. Server message: { "error" : "invalid_grant」 }
的錯誤。GoogleAnalytics ServiceAccount授權
def token
OAuth2::AccessToken.new(oauth_client, client_authorization.access_token,
expires_in: 1.hour
)
end
def oauth_client
OAuth2::Client.new("", "", {
authorize_url: "https://accounts.google.com/o/oauth2/auth",
token_url: "https://accounts.google.com/o/oauth2/token",
})
end
def client_authorization
@_client_authorization ||= client.authorization = service_account.authorize
end
def service_account
Google::APIClient::JWTAsserter.new({{ secret email address }},
"https://www.googleapis.com/auth/analytics.readonly",
key)
end
def key
Google::APIClient::KeyUtils.load_from_pem({{ secret keyfile path }}, {{ not so secret keyfile passphrase }})
end
def client
Google::APIClient.new(
application_name: {{ app name }},
application_version: 1,
)
end
我們知道的幾件事情:
- 密鑰文件/通工作正常。如果他們沒有,我們會看到「無效的密鑰文件或口令」
- 的代碼在開發(持續,如預期)
·虛擬的問題:
- 我們能否只產生一個補助(每小時)服務帳戶?
- 我們需要以某種方式共享服務器之間的撥款?
- 我們需要手動獲取一個令牌,並用它來代替?
- 是否存在不適用於本地主機的IP限制?
Thanks @Matt,spot on!我認爲這是一個刷新令牌問題,並將我的頭撞到了試圖重置的牆上等等。然後發現服務帳戶自動刷新標記並推斷出它只是時鐘,如上所述...所有這些都是爲了一個臭鼬鍾問題! – sbonami