simonspa / twitcurl

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

URL encoding error #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call twitCurl::search with a hashtag search string

What is the expected output? What do you see instead?

Expected output is the search results. Actual output is an authentication error.

What version of the product are you using? On what operating system?

r122 on Windows 8 x64

Please provide any additional information below.

oauth_signature needs to be generated with the unencoded URL which is done 
correctly, however the parameters then need to be encoded before being passed 
to cURL.

Here's what I've done to work around this and I can now search with hashtags:

std::vector<std::string> &split(const std::string &s, char delim, 
std::vector<std::string> &elems) {
    std::stringstream ss(s);
    std::string item("");
    while (std::getline(ss, item, delim)) {
        if (!item.empty())
            elems.push_back(item);
    }
    return elems;
}

bool twitCurl::performGet( const std::string& getUrl )

...

    std::string request("");
    /* Check for parameters */
    if (getUrl.find('?')!=std::string::npos)
    {
        std::size_t divide = getUrl.find_first_of('?')+1;
        std::string encodedparams("");
        std::string params=getUrl.substr(divide);
        std::vector<std::string> vparams;
        split(params,'&',vparams);
        for (unsigned int i=0;i<vparams.size();i++)
        {
            if (i>0) encodedparams+="&";
            std::size_t pos = vparams[i].find('=');
            if (pos!=std::string::npos)
                encodedparams+=vparams[i].substr(0,pos+1)+urlencode(vparams[i].substr(pos+1));
            else
                encodedparams+=vparams[i];
        }
        request=getUrl.substr(0,divide)+encodedparams;
    }
    else
        request=getUrl;

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

Original issue reported on code.google.com by sbd...@gmail.com on 18 Sep 2013 at 1:36