Please help me, what I’m doing wrong?
Endpoint: statuses/update.json
<?php date_default_timezone_set('UTC'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>endpoint: statuses/update</title>
</head>
<body>
<?
$oauth_consumer_key = rawurlencode('CONSUMER_KEY'); //from https://dev.twitter.com/apps/MY_APP/oauth
$oauth_nonce = rawurlencode(md5(time()));
$oauth_signature_method = rawurlencode('HMAC-SHA1');
$oauth_timestamp = rawurlencode(time());
echo '<p>UTC: '. date('H:i:s', time()).'</p>';
$oauth_token = rawurlencode('ACCESS_TOKEN'); //from https://dev.twitter.com/apps/MY_APP/oauth
$oauth_version = rawurlencode('1.0');
$oauth_consumer_secret = rawurlencode('CONSUMER_SECRET'); //from https://dev.twitter.com/apps/MY_APP/oauth
$oauth_token_secret = rawurlencode('ACCESS_TOKEN_SECRET'); //from https://dev.twitter.com/apps/MY_APP/oauth
$http_method = 'POST';
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$status = rawurlencode('helloworld');
//$parameter_str = 'include_entities=true&';
$parameter_str = 'oauth_consumer_key='.$oauth_consumer_key;
$parameter_str.= '&oauth_nonce='.$oauth_nonce;
$parameter_str.= '&oauth_signature_method='.$oauth_signature_method;
$parameter_str.= '&oauth_timestamp='.$oauth_timestamp;
$parameter_str.= '&oauth_token='.$oauth_token;
$parameter_str.= '&oauth_version='.$oauth_version;
$parameter_str.= '&status='.$status;
$base_str = $http_method;
$base_str.= '&';
$base_str.= rawurlencode($url);
$base_str.= '&';
$base_str.= rawurlencode($parameter_str);
$signing_key = $oauth_consumer_secret;
$signing_key.= '&';
$signing_key.= $oauth_token_secret;
$oauth_signature = rawurlencode(base64_encode(hash_hmac('sha1', $base_str, $signing_key, true)));
$header = 'Authorization: OAuth ';
$header.= 'oauth_consumer_key="'.$oauth_consumer_key;
$header.= '", oauth_nonce="'.$oauth_nonce;
$header.= '", oauth_signature="'.$oauth_signature;
$header.= '", oauth_signature_method="'.$oauth_signature_method;
$header.= '", oauth_timestamp="'.$oauth_timestamp;
$header.= '", oauth_token="'.$oauth_token;
$header.= '", oauth_version="'.$oauth_version.'"';
$header = array($header, 'Expect:', 'Content-Type: application/x-www-form-urlencoded');
$data = array('status'=>$status);
function send($url, $status, $header)
{
$ch = curl_init();
$f = fopen('request.txt', 'w');
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_VERBOSE => 1,
CURLOPT_STDERR => $f));
$response = curl_exec($ch);
fclose($f);
curl_close($ch);
return $response;
}
echo '<p>response: ';
print_r(send($url, $status, $header));
echo '</p>';
echo '<p>Request / Response:</p>';
echo '<textarea name="textarea" id="textarea" cols="125" rows="34">';
include 'request.txt';
echo '</textarea>';
?>
</body>
</html>
But I’m still getting the message: Could not authenticate you, code 32
Thanks.