HI all…
I am having troubles with status update…as i am completely new to this…please help me out.as soon as possible as it is urgent.
i am showing my code…
i am directly giving oauth-token and oauth_token_secret just for simplicity here…but i am successfully able to get those values…
here is my code…
<?php
function _http($url, $post_data = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
if(isset($post_data))
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
function buildAuthorizationHeader($oauth){
$r = 'Authorization: OAuth '; //header prefix
$values = array(); //temporary key=value array
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\""; //encode key=value string
$r .= implode(', ', $values); //reassemble
return $r; //return full authorization header
}//end buildAuthorizationHeader()
function sendRequest($oauth, $baseURI){
$header = array( buildAuthorizationHeader($oauth), 'Expect:'); //create header array and add 'Expect:'
$options = array(CURLOPT_HTTPHEADER => $header, //use our authorization and expect header
CURLOPT_HEADER => false, //don't retrieve the header back from Twitter
CURLOPT_URL => $baseURI, //the URI we're sending the request to
CURLOPT_POSTFIELDS=>$post, //this is going to be a POST - required
CURLOPT_RETURNTRANSFER => true, //return content as a string, don't echo out directly
CURLOPT_SSL_VERIFYPEER => false); //don't verify SSL certificate, just do it
$ch = curl_init(); //get a channel
curl_setopt_array($ch, $options); //set options
$response = curl_exec($ch); //make the call
curl_close($ch); //hang up
return $response;
}//end sendR
$ot="xxxxxxx";
$ost="XXXXXXXX";
$user_id="386511063";
$screen_name="uniqe_mohini";
$ct="XXXX";
$cs="XXXX";
$baseURI="http://api.twitter.com/1/statuses/update.json";
$params=array(
"status"=>"hello",
"oauth_consumer_key"=>$ct,
"oauth_nonce"=>time(),
"oauth_signature_method"=>"HMAC_SHA1",
"oauth_token"=>$ot,
"oauth_timestamp"=>time(),
"oauth_version"=>"1.0"
);
uksort($params,'strcmp');
foreach ($params as $k=>$v)
{
$pairs[]=rawurlencode($k)."=".rawurlencode($v);
}
$connectedstring=implode('&',$pairs);
$basestring="POST&".rawurlencode($baseURI)."&".rawurlencode($connectedstring);
$compositeKey=rawurlencode($cs)."&".rawurlencode($ost);
$signatur=base64_encode(hash_hmac('sha1',$basestring,$compositeKey,true));
$params['oauth_signature']=$signatur;
uksort($params,'strcmp');
$response = sendRequest($params, $baseURI);
echo $response;
?>
but i am getting the error “Could not authenticate with oauth”…
please help me out…what i am missing…
would be really thankful …