2010-06-09 168 views
5

有沒有人看到以下Curl調用/ Oauth請求如何構建的問題?
(我試圖得到一個正確的設置要求,所以我可以完成我的應用程序)

因此,我調用下面捲曲電話:Curl,twitter oauth問題

C:\>curl -v -k --data-urlencode "status=Testing2" -H "Authorization: OAuth realm='', oauth_nonce=1276107867blah, oauth_timestamp=1276107867, oauth_consumer_key=yJDLH7BDdVi1OKIINSV7Q, oauth_signature_method=HMAC-SHA1, oauth_version=1.0, oauth_signature=NWU4MDdlNjk0OGIxYWQ1YTkyNmU5YjU1NGYyOTczMmU5ZDg5 

YWNkNA ==,居留制= Testing2「http://twitter.com/statuses/update.xml?status=Testing2

,我收到這樣的:

* About to connect() to twitter.com port 80 (#0) 
* Trying 168.143.162.68... connected 
* Connected to twitter.com (168.143.162.68) port 80 (#0) 
> POST /statuses/update.xml?status=Testing2 HTTP/1.1 
> User-Agent: curl/7.20.1 (i386-pc-win32) libcurl/7.20.1 OpenSSL/0.9.8n zlib/1.2.5 libidn/1.18 libssh2/1.2.5 
> Host: twitter.com 
> Accept: */* 
> Authorization: OAuth realm='', oauth_nonce=1276106370blah, oauth_timestamp=1276106370, oauth_consumer_key=yJDLH7BDdVi1OKIINSV7Q, oauth_signature_method=HMAC-SHA1, oauth_version=1.0, oauth_signature=MjQzNDA1MGU4NGRmMWVjMzUwZmQ4YzE5NzMzY2I1ZDJlOTRkNmQ2Zg==, staus=Testing2 
> Content-Length: 15 
> Content-Type: application/x-www-form-urlencoded 
> 
< HTTP/1.1 401 Unauthorized 
< Date: Wed, 09 Jun 2010 18:00:22 GMT 
< Server: hi 
< Status: 401 Unauthorized 
< WWW-Authenticate: Basic realm="Twitter API" 
< X-Runtime: 0.00548 
< Content-Type: application/xml; charset=utf-8 
< Content-Length: 164 
< Cache-Control: no-cache, max-age=1800 
< Set-Cookie: k=209.234.229.21.1276106420885412; path=/; expires=Wed, 16-Jun-10 18:00:20 GMT; domain=.twitter.com 
< Set-Cookie: guest_id=127610642214871948; path=/; expires=Fri, 09 Jul 2010 18:00:22 GMT 
< Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCIm33h0pAToHaWQiJTkyMjllODE0NTdiYWE1%250AMWU1MzBmNjgwMTFiMDhkYjdlIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--8ebb3c62d461d28f8fda7b8adab642af66969f7e; domain=.twitter.com; path=/ 
< Expires: Wed, 09 Jun 2010 18:30:20 GMT 
< Vary: Accept-Encoding 
< Connection: close 
< 
<?xml version="1.0" encoding="UTF-8"?> 
<hash> 
    <request>/statuses/update.xml?status=Testing2</request> 
    <error>Could not authenticate with OAuth.</error> 
</hash> 
* Closing connection #0 

我的參數是設置像這樣:

var parameters = [encodeURIComponent("status="+status),encodeURIComponent("oauth_token="+ac_token),encodeURIComponent("oauth_consumer_key="+"yJDLH7BDdVi1OKIINSV7Q"),encodeURIComponent("oauth_nonce="+nonce,"oauth_signature_method=HMAC-SHA1"),encodeURIComponent("oauth_timestamp="+timestamp),encodeURIComponent("oauth_version=1.0")] 

var join = parameters.join("&"); 
var eparamjoin =encodeURIComponent(join); 

最關鍵的是,像這樣:

var key=con_secret+"&"+ac_secret; 

簽名基本字符串:

var signaturebs = "POST&"+encodeURIComponent(url)+"&"+eparamjoin; 

給這個:

POST&http%3A%2F%2Ftwitter.com%2Fstatuses%2Fupdate.xml&status%253DTesting2%26oauth_token%253D142715285-yi2ch324S3zfyKyJby6WDUZOhCsiQuKNUtc3nAGe%26oauth_consumer_key%253DyJDLH7BDdVi1OKIINSV7Q%26oauth_nonce%253D1276107867blah%26oauth_timestamp%253D1276107867%26oauth_version%253D1.0 

和簽名建立像這樣:

var hmac = Crypto.HMAC(Crypto.SHA1, signaturebs,key); 

var signature=Base64.encode(hmac); 

使得簽名:

NWU4MDdlNjk0OGIxYWQ1YTkyNmU5YjU1NGYyOTczMmU5ZDg5YWNkNA== 

任何幫助,將不勝感激謝謝!

回答

4

它可能就像一個URL問題一樣簡單。

你打電話:http://twitter.com/statuses/update.xml?status=Testing2

API文檔建議:http://api.twitter.com/1/statuses/update.xml?status=Testing2

他們前一段時間實施新的URL路徑,但我不知道什麼時候,或者如果他們關閉舊的。

+0

謝謝是的,這是一些東西,網址,也是我的標題想把版本放在第二個參數,而不是最後oauth。它終於工作了!論壇在這個問題上是免費的謝謝 – Darxval 2010-06-13 04:15:49