2017-12-12 1 views
0
23 앤미 웹 사이트가 API를 가지고

실패하고 그들이주는 following instructions :교환 인증 코드가 23 앤미의 API

Send a POST /token/ request with these parameters (client_id and client_secret are on your dashboard):

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" 

여기 내 코드입니다 :

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 

은 매우 간단는, 그러나 계속해서 다음과 같은 오류가 발생합니다 :

{"error_description"=>"redirect_uri doesn't match", "error"=>"invalid_request"} 

여기에 무엇이 누락 되었습니까?

답변

0

일반적으로 토큰을 가져올 때 OAuth2를 사용하면 지정된 리디렉션 URI가 OAuth 응용 프로그램의 리디렉션 URI와 일치해야합니다. 오류는 일치하지 않음을 나타냅니다.

또한 'Content-Type' => 'application/json' 헤더를 요청 용으로 설정 했습니까? 'Accept' => 'application/json'을 의미합니까?

+0

로리 (Lauri)는 URI가 리디렉션 URI와 일치하는지 확인했습니다. 아직 리디렉션 오류가 발생했습니다. –

관련 문제