I am building a service similar to TwitPic but for long messages. I am
using Echo OAuth and I wrote a unit testing script to show you what is
going on

On the back end I am opening the header, unfolding the content in X-
Verify-Credentials-Authorization to rebuilt the OAuth headers and I do
a GET http://api.twitter.com/1/account/verify_credentials.xml
The unit test will show you the content of X-Verify-Credentials-
Authorization and the header that is sent to Twitter.

What am I missing, please?

BTW: I plan to publish extensive code samples about Echo OAuth so that
other developers like me can learn how to do it right and stop bugging
you ;-)

The code of the unit test is
define ('oauth_http_provider', 'http://api.twitter.com/1/account/
$consumer = new OAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET,NULL);
$access_token = new OAuthToken($access_token['oauth_token'],
$request = OAuthRequest::from_consumer_and_token($consumer,
$access_token, 'GET', oauth_http_provider,NULL);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
$consumer, $access_token);
// clean up the header, Tweedom is like Twitpic, it prefers a clean
list without the 'Authorization: OAuth' label, please
$header = $request->to_header();
# Snip out the "Authorization: " part, and add a realm to be polite
$real_header = explode("Authorization: OAuth", $header);
$header = 'OAuth realm="http://api.twitter.com/";,' . $real_header[1];
# Keep the spaces between elements, even though we shouldn't have to
$header = str_replace(",", ", ", $header);

echo 'the http header for X-Verify-Credentials-Authorization: '.
$header.'<p><p>calling http://api.tweedom.com/1/jumbotweex/new.xm<p><P>Response:
$response = send_echo_request("POST", 'http://api.tweedom.com/1/
jumbotweex/new.xml', $header, $post, oauth_http_provider);

# Evaluate the response
if ($response)

function send_echo_request($http_method, $url, $auth_header,
$postData, $echo_url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);

        // Set our OAuth Echo headers
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'X-Verify-Credentials-Authorization: ' . $auth_header,
            'X-Auth-Service-Provider: ' . $echo_url

        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);

        $response = curl_exec($curl);
        //echo $response;
        if (!$response) {
                $response = curl_error($curl);
        return $response;

Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 

Reply via email to