dawoudt / twitcurl

Automatically exported from code.google.com/p/twitcurl
0 stars 0 forks source link

urls with parameters (i.e. .../home_timeline.json?count=1) needing authentication didn't work #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

first a big thanks for this piece of code. I detected some problems (incorrect 
signature) calling twitter URLs that need authentication and use parameters 
like count or since_id. I solved it by a small modification inside 
twitCurl::performGet() based on the idea that m_oAuth.getOAuthHeader() passes 
the parameters two times: inside getUrl and as dataStr. So I did a local copy 
of getUrl which doesn't include the pars and this seems to work. Here's my 
code, perhaps it helps ...

bool twitCurl::performGet( const std::string& getUrl )
{
    std::string dataStr( "" );
    std::string oAuthHttpHeader( "" );
    struct curl_slist* pOAuthHeaderList = NULL;

    /* Prepare standard params */
    prepareStandardParams();

    /* urlencode data */

    std::string localUrl = getUrl;
    size_t nPos = getUrl.find_first_of( "?" );
    if( std::string::npos != nPos )
    {
        std::string dataKey( "" );
        std::string dataValue( "" );
        dataStr = getUrl.substr( nPos + 1 );
        localUrl = getUrl.substr( 0, nPos );
        nPos = dataStr.find_first_of( "=" );
        if( std::string::npos != nPos )
        {
            dataKey = dataStr.substr( 0, nPos );
            dataValue = dataStr.substr( nPos + 1 );
            dataValue = urlencode( dataValue );
            dataStr.assign( dataKey );
            dataStr.append( "=" );
            dataStr.append( dataValue );
        }
    }

    /* Set OAuth header */
    m_oAuth.getOAuthHeader( eOAuthHttpGet, localUrl, dataStr, oAuthHttpHeader );
    if( oAuthHttpHeader.length() > 0 )
    {
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
        if( pOAuthHeaderList )
        {
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
        }
    }

    /* Set http request and url */
    curl_easy_setopt( m_curlHandle, CURLOPT_HTTPGET, 1 );
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, getUrl.c_str() );

    /* Send http request */
    if( CURLE_OK == curl_easy_perform( m_curlHandle ) )
    {
        if( pOAuthHeaderList )
        {
            curl_slist_free_all( pOAuthHeaderList );
        }
        return true;
    }
    if( pOAuthHeaderList )
    {
        curl_slist_free_all( pOAuthHeaderList );
    }
    return false;
}

Original issue reported on code.google.com by Gelbaerc...@Gelbaerchen.de on 17 Oct 2010 at 3:19

GoogleCodeExporter commented 8 years ago
Hi,

Thanks for the info. I will integrate your code in the library. It should fix 
the problem.

Thanks...

Original comment by swatkat....@gmail.com on 20 Oct 2010 at 1:49

GoogleCodeExporter commented 8 years ago
Hi,

The code committed today should fix this and other issues (direct message, 
friend create etc.)

Regards...

Original comment by swatkat....@gmail.com on 6 Nov 2010 at 3:01

GoogleCodeExporter commented 8 years ago

Original comment by swatkat....@gmail.com on 6 Mar 2011 at 3:58