2012-02-24 4 views
0

OAuth (http://oauth.rubyforge.org/)에 ruby ​​gem을 사용하고 있는데, 내가 치려고하는 제공자의 승인 헤더를 만들 수 없습니다. . 요청이 발생하면OAuth gem 서명 요청이 없습니다.

consumer = OAuth::Consumer.new(auth[:consumer_key], auth[:consumer_secret], { 
    :site => 'http://api.rdio.com', 
    :scheme => :header 
}) 

access_token = OAuth::AccessToken.new(consumer) 

ap access_token.post('/1', :method => 'search', :query => 'Robert', :types => 'User') 

는, 헤더는 호출에 존재하지 :

여기 내 코드입니다. 당신이이 다리의 OAuth을하려고하는 것처럼

OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\" 

답변

2

가 보이는 :

#<Net::HTTP::Post:0x7fbf149e91e0 
    @body_data = nil, 
    @header = { 
       "accept" => [ 
      [0] "*/*" 
     ], 
      "user-agent" => [ 
      [0] "Ruby" 
     ], 
     "content-length" => [ 
      [0] "0" 
     ], 
      "content-type" => [ 
      [0] "application/x-www-form-urlencoded" 
     ] 
    }, 

내가 말하는 겁니다 헤더

는 다음과 같습니다 하나입니다. 이 코드가 효과가 있는지보십시오.

편집 : 업데이트 코드 샘플

gem 'oauth' 
require 'oauth' 
require 'net/http' 

consumer = OAuth::Consumer.new('ENTER_KEY', 'ENTER_SECRET', {   
           :site => 'http://api.rdio.com',   
           :scheme => :header   
}) 

resp = consumer.request(:post, '/1/search', nil, {}, 'method=search&query=Robert&types=User', { 'Content-Type' => 'application/x-www-form-urlencoded' }) 
puts resp.code + "\r\n" 
puts resp.body 

편집 : 추가 촬영 HTTP 스트림

POST /1/search HTTP/1.1 
Content-Type: application/x-www-form-urlencoded 
Accept: */* 
User-Agent: OAuth gem v0.4.5 
Content-Length: 37 
Authorization: OAuth oauth_consumer_key="REDACTED_KEY", oauth_nonce="dwp8m2TGPHQNx3A7imLi7OkAULL7c0IWbTKefPXCsAY", oauth_signature="LxDZn6UNFLY%2FaXItu6MPK5a11js%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1330193449", oauth_version="1.0" 
Connection: close 
Host: api.rdio.com 

method=search&query=Robert&types=UserHTTP/1.1 200 OK 
X-Mashery-Responder: mashery-web1.LAX 
Content-Type: application/json 
Vary: Accept-Encoding 
Vary: Accept-Language, Cookie 
Content-Language: en 
Cache-Control: no-cache 
X-Version: 11.1 
Accept-Ranges: bytes 
Date: Sat, 25 Feb 2012 18:10:50 GMT 
Server: Mashery Proxy 
Content-Length: 2763 
Connection: close 

{"status": "ok", "result": {"person_count": 9603, "track_count": 93409, "number_results": 200, "playlist_count": 205, "results": ***TRUNCATED RESULTS FOR BREVITY*** 
+0

음 : 헤더 = { "콘텐츠 유형"=> [ [0] "application/x-www-form-ur lencoded " ] "수락 "=> [ [0]"*/* " ] "사용자 에이전트 "=> [ [0]"루비 " ] "콘텐츠 길이 "= > [ [0] "37" ] } –

+0

확인 된 작동 코드 예제 및 http 스트림으로 답변을 업데이트했습니다. 나는 루비 1.9.3 및 oauth 보석 v0.4.5를 실행 중입니다 – JoshSchlesinger

+0

놀라워요, 고마워요! –

관련 문제