Reputation: 2693
I'm trying to post a status update to the Chinese microblogging website Sina Weibo, via PHP/cURL and OAuth2. I'm running into this error:
{"error":"auth faild!","error_code":21301,"request":"/2/statuses/update.json"}
My 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);
?>
I authorized the app with the OAuth2 scope all
and the token is valid.
What could be the reason for the error?
Upvotes: 1
Views: 591
Reputation: 39375
Remove your http header
'Content-Type: application/x-www-form-urlencoded'
Replace post fields with:
CURLOPT_POSTFIELDS => http_build_query($postData)
And now Be Happy!
Upvotes: 2