2011-12-29 18 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