2011-12-29 56 views
6

我使用meltingice's API for TwitPic,當我嘗試上傳圖片時,出現401錯誤消息「無法驗證您(標頭被Twitter拒絕)」。401 - 「無法驗證您(標頭被Twitter拒絕)」。當試圖用PHP上傳一張圖片到TwitPic

我的頭(從HTTP請求2對象檢索)是:

Array 
(
    [user-agent] => HTTP_Request2/2.0.0 (http://pear.php.net/package/http_request2) PHP/5.2.17 
    [x-verify-credentials-authorization] => OAuth realm="http://api.twitter.com/", oauth_consumer_key="****************", oauth_signature_method="HMAC-SHA1", oauth_token="#########-******************", oauth_timestamp="1325192643", oauth_nonce="***********", oauth_version="1.0", oauth_signature="****************%3D" 
    [x-auth-service-provider] => https://api.twitter.com/1/account/verify_credentials.json 
    [content-type] => multipart/form-data 
) 

我確信,在verify_credentials簽名是使用GET,我看不到任何其他的問題。

我在做什麼錯?

謝謝:)

編輯:這是我的源代碼。

$venue = $this->Venue->findById($venueId); 
$twitterData = json_decode($venue['Venue']['twitter_data']); 
$token = $twitterData->token; 
$secret = $twitterData->secret; 
$this->Twitter->loginTwitterUser($token, $secret); 
require_once(WWW_ROOT.'twitpic/TwitPic.php'); 

$twitpic = new TwitPic('**********', '*******', '*********', $token, $secret); 


$result['result'] = $twitpic->upload(array('media'=> '/home/todays/public_html/tsm/app/webroot/files/uploads/LOGOA7V1_10.png', 'message'=> 'test')); 

而且我敢肯定,令牌,密,和應用程序憑據是正確的,因爲他們在我的Twitter API的工作沒有任何問題。我還仔細檢查了Twitpic API密鑰。

+0

嘗試,圍繞着try和catch你的代碼,看看它是否會拋出異常。你也應該啓用錯誤,看看是否有任何你看不到的錯誤。還有:你爲什麼還要登錄Twitter?當你使用TwitPic時,這真的很有必要嗎? – 2012-01-13 16:31:50

+0

嘗試獲取發送給TwitPic的實際HTTP請求。有幾種方法可以做到這一點:netcat,fiddler,wireshark ... – 2012-01-13 16:48:36

+0

@RunarJørgensen 它引發了一個自定義異常,並且我進入拋出異常以接收標題數組的地方。 – 2012-01-16 05:37:12

回答

2

檢查TwitPic documentation後,我注意到,401錯誤解釋:This method will return a 401 Unauthorized if the OAuth header was not present or could not be verified with Twitter.

你說你做確保verify_credentials簽名是使用GET而API只接受POST。也許這是你的問題?

下面是一個選擇您使用的API的示例代碼:

+0

'verify_credentials'只接受GET [見這裏](https://dev.twitter.com/docs/api/1/get/account/verify_credentials),我使用的API使用GET。 – 2012-01-06 23:26:55

+0

嘗試包括你的代碼。人們會更容易檢查一切是否正常。 – 2012-01-06 23:40:44