{"error":"Could not authenticate with OAuth.","request":"\/1\/statuses\/update.json"}


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…

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);

            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        $response = curl_exec($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

foreach ($params as $k=>$v)


$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 …


My advice is to use tmhOAuth - there are so many edge cases to get right that using a tested library is really the preferable way to go here.

Here’s an example on how to post a tweet using it: https://github.com/themattharris/tmhOAuth/blob/master/examples/tweet.php

In the code you’ve listed, it looks like _http is never called, and you’re not actually sending the POST body in the sendRequest call. That alone would be enough to invalidate the signature.


{“error”:“Could not authenticate with OAuth.”,“request”:"/1/statuses/update.json"}

Trying to set up next srcipts plug in. filled in all fields on form with info provided by twitter.
Was requested to send test and this was the result.

Any ideas please


Please start a new discussion instead of replying to one which was last updated 47 weeks ago. When doing so, please include information about exactly what you’ve tried - libraries, configuration, and concise examples of the code you’re using to issue requests to the API.