The 23andme web site has an API and they give the following instructions:
23andme网站有一个API,他们提供以下说明:
Send a POST /token/ request with these parameters (client_id and client_secret are on your dashboard):
使用这些参数发送POST /令牌/请求(client_id和client_secret在您的仪表板上):
curl https://api.23andme.com/token/
-d client_id=xxx \
-d client_secret=yyy \
-d grant_type=authorization_code \
-d code=zzz \
-d "redirect_uri=https://localhost:5000/receive_code/"
-d "scope=basic%20rs3094315"
Here's my code:
这是我的代码:
require 'net/http'
require 'openssl'
require 'json'
def get_token
uri = URI.parse("https://api.23andme.com/token")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path,
initheader = {'Content-Type' =>'application/json'})
request.set_form_data({"client_id" => 'bc81e2eb4fa77a0a8a2344aa99b5fb1e',
"client_secret" => 'd19160ac880a0d7a13abb87b90f66d8e',
"grant_type" => 'authorization_code',
"code" => 'a210a1d0beba7e3a1ef7f4133d7a3d3c',
"redirect_uri" => 'http://localhost:3000',
"scope" => 'names basic haplogroups relatives'})
response = https.request(request)
data = JSON.load response.read_body
return data
end
puts get_token
quite straightforward, however I keep getting the following error:
非常简单,但我不断收到以下错误:
{"error_description"=>"redirect_uri doesn't match", "error"=>"invalid_request"}
What am I missing here?
我在这里想念的是什么?
1 个解决方案
#1
0
Typically with OAuth2 when fetching token, given redirect URI should match the redirect URI of OAuth application. The error indicates that it does not match.
通常在获取令牌时使用OAuth2,给定重定向URI应与OAuth应用程序的重定向URI匹配。该错误表示它不匹配。
Also you are setting 'Content-Type' => 'application/json'
header for the request, do you mean 'Accept' => 'application/json'
?
你也为请求设置'Content-Type'=>'application / json'标题,你的意思是'Accept'=>'application / json'吗?
#1
0
Typically with OAuth2 when fetching token, given redirect URI should match the redirect URI of OAuth application. The error indicates that it does not match.
通常在获取令牌时使用OAuth2,给定重定向URI应与OAuth应用程序的重定向URI匹配。该错误表示它不匹配。
Also you are setting 'Content-Type' => 'application/json'
header for the request, do you mean 'Accept' => 'application/json'
?
你也为请求设置'Content-Type'=>'application / json'标题,你的意思是'Accept'=>'application / json'吗?