google-api-client突然回复“无效请求”

时间:2013-10-03 19:25:03

标签: google-api-client google-api-ruby-client

我使用服务帐户已经运行了几周的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"
}

难倒!

1 个答案:

答案 0 :(得分:0)

行。我想到了。这与user_email有关。我正在从一个文件中读取它,忘了关闭换行,所以它反对一个格式错误的电子邮件地址。