1
我試圖讓Rails和Digg API的OAuth一起玩。我使用oauth寶石(紅寶石一個,而不是導軌)。使用Digg API的OAuth
我的代碼看起來大約是這樣的:
@consumer = OAuth::Consumer.new(API_KEY, API_SECRET,
:scheme => :header,
:http_method => :post,
:oauth_callback => "http://locahost:3000",
:request_token_url => 'http://services.digg.com/1.0/endpoint?method=oauth.getRequestToken',
:access_token_url => 'http://services.digg.com/1.0/endpoint?method=oauth.getAccessToken',
:authorize_url => 'http://digg.com/oauth/authorize')
@request_token = DiggController.consumer.get_request_token({
:oauth_callback => "http://xx.xxx.xxx.x:3000/digg/callback"
}, {
'Content-Type' => 'application/x-www-form-urlencoded'
})
session[:request_token] = @request_token.token
session[:request_token_secret] = @request_token.secret
redirect_to @request_token.authorize_url
這是由這本書在什麼樣的寶石文檔給了我而言。但是,當調用@ consumer.get_request_token時,Digg會向我吐出一個「400錯誤請求」錯誤。我無法弄清楚我做錯了什麼。有任何想法嗎?
編輯:代碼已更新,添加了Wireshark輸出。我的錯誤現在是「需要401授權」。從Wireshark的
輸出:
POST /1.0/endpoint?method=oauth.getRequestToken HTTP/1.1
Accept: */*
Connection: close
User-Agent: OAuth gem v0.3.6
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth oauth_nonce="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_callback="http%3A%2F%2Fxx.xxx.xxx.x%3A3000%2Fdigg%2Fcallback",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1268687137",
oauth_consumer_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_signature="xxx%2Bxxxxxxxxxxxxxxx%2Fxxxxxxx%3D", oauth_version="1.0"
Content-Length: 48
Host: services.digg.com
Content-Type=application%2fx-www-form-urlencoded
HTTP/1.1 401 Authorization Required
Date: Mon, 15 Mar 2010 21:05:37 GMT
Server: Apache
X-Powered-By: PHP/5.2.9-digg8
Cache-control: private
X-RateLimit-Current: 1
X-RateLimit-Max: 1000
X-RateLimit-Reset: 3600
X-Digg-Api-Version: 1.0
Accept-Ranges: bytes
Content-Length: 111
Keep-Alive: timeout=5, max=9998
Connection: Keep-Alive
Content-Type: text/xml;charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<error code="5001" message="Invalid
signature" timestamp="1268687137"/>
感謝您的提示,但我甚至從未進入Digg授權頁面。目前似乎唯一重要的參數是request_token_url。 – Karl 2010-03-11 05:30:03
使用tcpdump或Wireshark來查看在HTTP 400正文中digg的答案。順便提一下,http://community.freshbooks.com/forums/viewtopic.php?pid=26769是否有幫助? – vladr 2010-03-11 06:05:53
我使用localhost:3000像Oauth連接到Twitter和MyspaceID時的回調。所以不能阻止 – shingara 2010-03-11 09:14:05