2011-12-27 74 views
0

我所試圖做的事:連接到通過PHP中的tumblr API v2和能夠創造新職位無法使用的tumblr API V2使POST請求

問題:的API響應總是類似於Invalid OAuth credentials. Unable to get info

奇怪的部分是,我能夠連接到API(http://www.tumblr.com/docs/en/api/v2)沒有問題,當我做一個GET請求,但是當我嘗試創建POST時,必須有一些我的簽名必須做錯。

這裏是我的代碼:

$params = array("type" => "quote", "quote"=>"test"); 
$consumer = new OAuthConsumer($consumer_key, $consumer_secret, null); 
$token = new OAuthConsumer($access_token['oauth_token'], $consumer_secret); 
$req_req = OAuthRequest::from_consumer_and_token($consumer, $token, 
"POST", 'http://api.tumblr.com/v2/blog/MY_URL/post', $params); 
$req_req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), 
$consumer, $token, null); 
$result = $req_req->to_postdata(); 

$ch = curl_init('http://www.tumblr.com/api/write'); 
curl_setopt($ch, CURLOPT_URL, 'http://www.tumblr.com/api/write'); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $result); 

$result一個var_dump呼應以下

oauth_consumer_key=xxxxxxxx&oauth_nonce=xxxxxxx&oauth_signature=xxxxxx 
&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1325033502&oauth_token=xxxxxx 
&oauth_version=1.0"e=test&type=quote 

我不知道該curl_init必須調用http://www.tumblr.com/api/write,但我也試圖與api.tumblr.com/v2/blog/{base-hostname}/post沒有運氣

我也檢查了所有變量,看看令牌是否可以,它們似乎工作正常。

任何暗示正確的方向將不勝感激,因爲我去了谷歌的第30頁,我只是看到與我有同樣問題的人。

回答

0

我一直在成功與this library,這是一年前寫的。

我檢查了捲曲之前的結果轉儲,它看起來或多或少與你的一樣,所以我不知道有什麼區別。