views:

48

answers:

2

Ive cracked oAuth and have my class file for it. I'm at the last stage of posting a tweet and all works except all the words are joined with a plus sign in the tweet.

Changing anything results in the signature been incorrect and twitter returns 401 error.

So how does one remove the pluses? Post function below:

function post($token, $tokenSecret, $status)
{
    // Default params
    $params = array(
        "oauth_version" => "1.0",
        "oauth_nonce" => time(),
        "oauth_timestamp" => time(),
        "oauth_consumer_key" => $this->key,
        "oauth_signature_method" => "HMAC-SHA1",
        "oauth_token" => $token,
        "status" => $status
     );
    uksort($params, 'strcmp');

    // convert params to string 
        foreach ($params as $k => $v) {$pairs[] = $this->_urlencode_rfc3986($k).'='.$this->_urlencode_rfc3986($v);}
        $concatenatedParams = implode('&', $pairs);

        // form base string (first key)
        $baseString= "POST&".$this->_urlencode_rfc3986($this->request_statuses_url)."&".$this->_urlencode_rfc3986($concatenatedParams);
        // form secret (second key)
        $secret = $this->_urlencode_rfc3986($this->secret)."&".$this->_urlencode_rfc3986($tokenSecret);
        // make signature
        $sig = $this->_urlencode_rfc3986(base64_encode(hash_hmac('sha1', $baseString, $secret, TRUE)));

     // BUILD URL
        $url = $this->request_statuses_url; // twitter update url
        $paramString = $concatenatedParams."&oauth_signature=".$sig;

     // Send to cURL
     $result = $this->_http($url, $paramString);

     if($result['httpCode'] == '200'){

        // Return array
        return $result;
    }
    else{

        // Error
        show_error($result['httpCode'], $result['httpCode']);
        return FALSE;
    }       
}
+1  A: 

Is $status your tweet? Take a look at the POST request before you post it, my guess is _urlencode_rfc3986() converts it so that you get "$status=This+is+my+tweet" when you want "$status=This is my tweet"

waitinforatrain
yes it does, but twitter requires that you url_encode all your params and since your params make up your base signature I cant remove them in the actual post fields because then twitter returns a 401 error. I dono. There documentation does not help either.
Derrick
A: 

Twitter is not supporting "+" as escape for spaces, which as far as I know is a violation of the standard.

You have to replace the the + with %20.

nhnb
yeah - there was a problem with url_encodeing. fixed it up. thanks
Derrick