2014-02-25 40 views
1

我试图通过PHP/cURL和OAuth2向中文微博网站新浪微博发布status update。 我遇到了此问题:如何通过OAuth2向新浪微博发布状态更新?

{"error":"auth faild!","error_code":21301,"request":"/2/statuses/update.json"}

我的PHP:

<?php 
$ch = curl_init('https://api.weibo.com/2/statuses/update.json'); 
$headers = array(
'Authorization: Bearer '.$access_token, 
'Content-Type: application/x-www-form-urlencoded'); 
$postData = array('access_token' => '2.00x123456789', 'status' => 'hello'); 

curl_setopt_array($ch, array(
CURLOPT_SSL_VERIFYPEER => FALSE, 
CURLOPT_SSL_VERIFYHOST => TRUE, 
CURLOPT_POST => TRUE, 
CURLOPT_RETURNTRANSFER => TRUE, 
CURLOPT_HTTPHEADER => $headers, 
CURLOPT_POSTFIELDS => $postData 
)); 

$response = curl_exec($ch); 
echo $response; 

curl_close($ch);   
?> 

我授权使用的OAuth2范围all应用程序和令牌是有效的。 错误的原因是什么?

回答

2

删除你的HTTP头

'Content-Type: application/x-www-form-urlencoded'

替换为后场:

CURLOPT_POSTFIELDS => http_build_query($postData) 

现在幸福!

+0

我现在真的很开心!非常感谢! – Uli