I have tested the header by this way:
create header by twitcurl, and then use it in qtweetlib, it is OK,
but  fail when opposite.
So I think maybe the problem is how curl & openssl requesting token, but I have 
no idea about it....


At 2010-11-01 09:07:01,"engine.start" <477914...@163.com> wrote:
I need your help....


At 2010-10-29 17:11:55,"engine.start" <477914...@163.com> wrote:
Hi Tom,
Thanks for your reply, I have fix the problem you mentioned, but it still 
return "Failed to validate oauth signature and token".......

sigBase is -----------------------------------
POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Faccess_token&oauth_consumer_key%3D###############%26oauth_nonce%3D128834239529a%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1288342395%26oauth_version%3D1.0%26x_auth_mode%3Dclient_auth%26x_auth_password%3D######%26x_auth_username%3D#####

oAuthHttpHeader is ---------------------------------
Authorization: OAuth 
oauth_consumer_key="#################",oauth_nonce="128834239529a",oauth_signature="SVMgVYdS%2Bf%2FQXM8sNQKlC8FScSE%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1288342395",oauth_version="1.0"

body is 
x_auth_mode%3Dclient_auth%26x_auth_password%3D#####%26x_auth_username%3D######

modified code :
bool twitCurl::xAuthAccessToken()
{
    bool retVal = false;
    FILE *fp = fopen("/tmp/twitter/xauth","w");
    std::string url(oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL);
   
    if( isCurlInit() )
    {
        std::string body = "x_auth_mode=client_auth&x_auth_password=" + 
urlencode(m_twitterPassword) + "&x_auth_username=" + 
urlencode(m_twitterUsername);

        std::string dataStr("");

        dataStr = body;
       
        url += (std::string("?") + body);

        std::string oAuthHeader( "" );
        struct curl_slist* pOAuthHeaderList = NULL;
           
        CURL* curlHandle = curl_easy_init();;
       
        std::string localUrl = url;
        size_t nPos = url.find_first_of( "?" );
        if( std::string::npos != nPos )
        {
            localUrl = url.substr( 0, nPos );               
        }
       
       
        std::string oAuthHttpHeader("");
        /* Set OAuth header */
        m_oAuth.getOAuthHeader( eOAuthHttpPost, localUrl, dataStr, 
oAuthHttpHeader );
       
        if( oAuthHttpHeader.length() > 0 )
        {
            pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, 
oAuthHttpHeader.c_str() );
            if( pOAuthHeaderList )
            {
                curl_easy_setopt( curlHandle, CURLOPT_HTTPHEADER, 
pOAuthHeaderList );
            }
        }
   
        /* Set http request, url and data */
        curl_easy_setopt( curlHandle, CURLOPT_POST, 1 );
        curl_easy_setopt( curlHandle, CURLOPT_USE_SSL, CURLUSESSL_CONTROL);
        curl_easy_setopt( curlHandle, CURLOPT_SSLVERSION, 
CURL_SSLVERSION_SSLv3);
        curl_easy_setopt( curlHandle, CURLOPT_SSL_VERIFYPEER, 0L);
        curl_easy_setopt( curlHandle, CURLOPT_SSL_VERIFYHOST, 0L);
        curl_easy_setopt( curlHandle, CURLOPT_URL, url.c_str() );
        curl_easy_setopt( curlHandle, CURLOPT_WRITEFUNCTION, write_data );
        curl_easy_setopt( curlHandle, CURLOPT_WRITEDATA, fp );
       
        body = urlencode( body );
       
        if( body.length() )
        {
            curl_easy_setopt( curlHandle, CURLOPT_COPYPOSTFIELDS, body.c_str() 
);
        }
   
        /* Send http request */
        CURLcode code = curl_easy_perform( curlHandle );
        if( code == CURLE_OK )
        {
            retVal = true;
        }
        else
        {
            retVal = false;
        }
      
        if( pOAuthHeaderList )
        {
            curl_slist_free_all( pOAuthHeaderList );
        }
        fclose(fp);
    }
    return retVal;
}

Thanks.






At 2010-10-29 16:27:13,"Tom van der Woerdt" <i...@tvdw.eu> wrote:

>Your x_auth_* parameters aren't in your base string. This might cause it.
>
>Tom
>
>
>On Oct 29, 2010, at 6:10 AM, udta <477914...@163.com> wrote:
>
>> Hi,
>> 
>> I am using libtwitcurl, and converting oAuth to xAuth, but I got
>> "Failed to validate oauth signature and token".
>> I compare all I can printf data to libQtweet(xauth succesful), and
>> couldn't found any error....
>> 
>> 
>> sigBase is:
>> POST&https%3A%2F%2Fapi.twitter.com%2Foauth
>> %2Faccess_token&oauth_consumer_key%3D**************%26oauth_nonce
>> %3D1288319703364%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp
>> %3D1288319703%26oauth_version%3D1.0
>> 
>> oAuthHttpHeader is:
>> Authorization: OAuth
>> oauth_consumer_key="*************",oauth_nonce="1288319703364",oauth_signature="SUlWtiHEc6wZJwiY9bZDgRkSyKE
>> %3D",oauth_signature_method="HMAC-
>> SHA1",oauth_timestamp="1288319703",oauth_version="1.0"
>> 
>> 
>> This is my code:
>> 
>> bool twitCurl::xAuthAccessToken()
>> {
>>    bool retVal = false;
>>    FILE *fp = fopen("/tmp/twitter/xauth","w");
>>    std::string
>> url(oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL);
>> 
>>    if( isCurlInit() )
>>    {
>>        std::string body = "x_auth_mode=client_auth&x_auth_password="
>> + urlencode(m_twitterPassword) + "&x_auth_username=" +
>> urlencode(m_twitterUsername);
>> 
>>        std::string dataStr("");
>> 
>>        dataStr = body;
>> 
>>        url += (std::string("?") + body);
>> 
>>        std::string oAuthHeader( "" );
>>        struct curl_slist* pOAuthHeaderList = NULL;
>> 
>>            CURL* curlHandle = curl_easy_init();;
>> 
>>            std::string localUrl = url;
>>            size_t nPos = url.find_first_of( "?" );
>>            if( std::string::npos != nPos )
>>            {
>>                localUrl = url.substr( 0, nPos );
>>            }
>>            dataStr = urlencode( dataStr );
>> 
>>            std::string oAuthHttpHeader("");
>>            /* Set OAuth header */
>>            m_oAuth.getOAuthHeader( eOAuthHttpPost, localUrl, dataStr,
>> oAuthHttpHeader );
>> 
>>            if( oAuthHttpHeader.length() > 0 )
>>            {
>>                pOAuthHeaderList =
>> curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
>>                if( pOAuthHeaderList )
>>                {
>>                    curl_easy_setopt( curlHandle, CURLOPT_HTTPHEADER,
>> pOAuthHeaderList );
>>                }
>>            }
>> 
>>            /* Set http request, url and data */
>>            curl_easy_setopt( curlHandle, CURLOPT_POST, 1 );
>>            curl_easy_setopt( curlHandle, CURLOPT_USE_SSL,
>> CURLUSESSL_CONTROL);
>>            curl_easy_setopt( curlHandle, CURLOPT_SSLVERSION,
>> CURL_SSLVERSION_SSLv3);
>>            curl_easy_setopt( curlHandle, CURLOPT_SSL_VERIFYPEER, 0L);
>>            curl_easy_setopt( curlHandle, CURLOPT_SSL_VERIFYHOST, 0L);
>>            curl_easy_setopt( curlHandle, CURLOPT_URL, url.c_str() );
>>            curl_easy_setopt( curlHandle, CURLOPT_WRITEFUNCTION,
>> write_data );
>>            curl_easy_setopt( curlHandle, CURLOPT_WRITEDATA, fp );
>> 
>>            if( dataStr.length() )
>>            {
>>                curl_easy_setopt( curlHandle, CURLOPT_COPYPOSTFIELDS,
>> dataStr.c_str() );
>>            }
>> 
>>            /* Send http request */
>>            CURLcode code = curl_easy_perform( curlHandle );
>>            if( code == CURLE_OK )
>>            {
>>                retVal = true;
>>            }
>>            else
>>            {
>>                retVal = false;
>>            }
>> 
>>            if( pOAuthHeaderList )
>>            {
>>                curl_slist_free_all( pOAuthHeaderList );
>>            }
>>            fclose(fp);
>>    }
>>    return retVal;
>> }
>> 
>> 
>> 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
>
>-- 
>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







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

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