Yes, I know there're already plenty of questions with this same topic,
but I cannot really find out the one suite for me.
I use C++ and libcurl to make a HTTP POST request, and here are some
ingredients that I used for POST requests.

Signature base string
POST&https%3A%2F%2Fapi.twitter.com%2Foauth
%2Faccess_token&oauth_consumer_key%3DMYCONSUMERKEY%26oauth_nonce
%3DXZZJd88qUu25L8wpylQ6%26oauth_signature_method%3DHMAC-
SHA1%26oauth_timestamp%3D1285924211%26oauth_version%3D1.0%26x_auth_mode
%3Dclient_auth%26x_auth_password%3DMYPASSWORD%26x_auth_username
%3Dxoancer%40seed9.com

POST Body
x_auth_username=xoancer
%40seed9.com&x_auth_password=MYPASSWORD&x_auth_mode=client_auth

HTTP Header
Authorization: OAuth oauth_nonce="XZZJd88qUu25L8wpylQ6",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1285924211",
oauth_consumer_key="MYCONSUMERKEY",
oauth_signature="l4L1%2Fn7w3P7U0lcxvkTizusF2TY%3D",
oauth_version="1.0"

I believe signature generating is not the problem since my program
makes the proper one when it runs with the example at
http://dev.twitter.com/pages/xauth. But without the signature
parameter, I cannot found out what's wrong since every other
parameters are just a given constants(except nonce, but he doesn't
really matter I think.).
Maybe I missed something in using libcurl, since it's first time for
me to use this library, especially in setting HTTP Header. Follows are
my source codes for libcurl parts.

        curl_global_init(CURL_GLOBAL_ALL);

        CURL *curl;
        curl = curl_easy_init();

        curl_easy_reset(curl);
        curl_easy_setopt(curl, CURLOPT_URL, baseUrl.c_str());
// baseUrl == https://api.twitter.com/oauth/access_token

        curl_easy_setopt(curl, CURLOPT_POST, true);

        string postbody;
        for(int i=7;i>=5;i--) postbody += "&" + params[i].first + "=" +
urlenc(params[i].second);
        postbody = postbody.substr(1);
// postbody == x_auth_username=xoancer
%40seed9.com&x_auth_password=MYPASSWORD&x_auth_mode=client_auth

        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postbody.c_str());

        string header = "Authorization: OAuth " + params[1].first + "=\"" +
params[1].second + "\", " + params[2].first + "=\"" + params[2].second
+ "\", " + params[3].first + "=\"" +
                params[3].second + "\", " + params[0].first + "=\"" +
params[0].second + "\", oauth_signature=\"";

        header += urlenc(base64encoded);
        header += "\", oauth_version=\"1.0\"";
// header == Authorization: OAuth oauth_nonce="XZZJd88qUu25L8wpylQ6",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1285924211",
oauth_consumer_key="MYCONSUMERKEY",
oauth_signature="l4L1%2Fn7w3P7U0lcxvkTizusF2TY%3D",
oauth_version="1.0"

        curl_slist* responseHeaders = NULL ;
    responseHeaders = curl_slist_append( responseHeaders ,
header.c_str() ) ;
    curl_easy_setopt( curl , CURLOPT_HTTPHEADER , responseHeaders ) ;

        string res;
        curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, write_callback );
    curl_easy_setopt( curl, CURLOPT_WRITEDATA, &res );

        curl_easy_setopt(curl, CURLOPT_HEADER, true);

        curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, false);

        CURLcode rc = curl_easy_perform(curl);


If you find some mistakes, please tell me. Thanks.

-- 
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: 
http://groups.google.com/group/twitter-development-talk

Reply via email to