几周以来,我一直在使用服务帐户运行 Ruby 脚本,但今天当我尝试使用以下函数构建客户端时,我收到了“无效请求”:
def build_client(user_email)
client = Google::APIClient.new
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 => SERVICE_ACCOUNT_EMAIL,
:signing_key => Google::APIClient::KeyUtils.load_from_pkcs12(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret"),
:person => user_email
)
client.authorization.fetch_access_token!
return client
end
服务帐户有生命周期吗?我尝试创建另一个服务帐户并使用它,但得到相同的结果:
Authorization failed. Server message: (Signet::AuthorizationError)
{
"error" : "invalid_request"
}
难倒!