我正在尝试使用Signet::Oauth2::Client从getresponse.com获取访问令牌
client = Signet::OAuth2::Client.new(
client_id: GET_RESPONSE_CLIENT_ID,
client_secret: GET_RESPONSE_CLIENT_SECRET,
token_credential_uri: 'https://api.getresponse.com/v3/token',
redirect_uri: my_callback_uri,
grant_type: 'authorization_code',
code: the_code_i_got_from_get_response
)
response = client.fetch_access_token!但是,Get Response始终返回以下内容:
{"error"=>"invalid_client", "error_description"=>"Client credentials were not found in the headers"}我已经很容易地用curl完成了这个请求。它会成功返回令牌。
curl -v -u client_id:client_secret https://api.getresponse.com/v3/token -d "grant_type=authorization_code&code=abc123thisisthecode&redirect_uri=https://myserver.com/callback"我已经尝试了一百万种方法,并阅读了客户源代码,但我没有发现自己做错了什么。我将继续阅读文档,但在此期间,我想我应该向stackoverflow的专业人士请教。有人知道答案吗?这里是接口文档https://apidocs.getresponse.com/v3/oauth2
发布于 2019-01-25 11:07:37
遇到了类似的问题。我遵循了下面的步骤,并为自己工作。
第1步加载从google开发人员控制台获得的凭据。
client_secrets = Google::APIClient::ClientSecrets.load("#{Rails.root}/zenledger_ga_secrets.json")
auth_client = client_secrets.to_authorization
auth_client.update!(
:scope => 'email profile https://www.googleapis.com/auth/analytics.readonly',
:grant_type => "authoriation_code",
:response_type => 'code',
:redirect_uri => 'http://localhost:3001/admin/oauth2callback',
:additional_parameters => {
"access_type" => "offline", # offline access
"include_granted_scopes" => "true", # incremental auth
}
)步骤2.加载您的Signet客户端以获取访问所需API所需的访问令牌。
@client = Signet::OAuth2::Client.new(
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
:token_credential_uri => 'https://oauth2.googleapis.com/token',
:client_id => ''xxxxxxxxxx',
:client_secret => 'xxxxxxxxxx',
:scope => 'email profile',
:redirect_uri => 'http://localhost/admin/oauth2callback'
)
@client.code = auth_code
@client.fetch_access_token!备注auth_code是由谷歌在重定向URL中发送的。您可以在应用程序的oauth2callback url中以参数形式获取它们。
https://stackoverflow.com/questions/49734461
复制相似问题