Overview
Features
Download
Documentation
Community
Add-Ons & Services

Trying to use HTTPSClientSession for Twitter OAUTH

Please post support and help requests here.

Trying to use HTTPSClientSession for Twitter OAUTH

Postby PlumCantaloupe » 07 Aug 2013, 23:22

Hi everyone,

I must admit networking code is a bit new to me but I am trying to write a basic class to get a portable user stream from Twitter for an art installation. As SHA1 OAUTH is now mandatory I figured Poco and HTTPSClientSession is the way to go. I have all the OAUTH credentials being created correctly (tested through a bash script) but when I try to set up the following code I get no response at all. Strangely, when I add an error into the credentials purposely I do get a authorization denied response from twitter ...

I basically have two questions.
1. Is there something I am doing wrong below to result in the request hanging within the thread I have waiting for a response that never comes?
2. Since it is a user stream what would be the most appropriate way to keep the datasocket open so I continuously read the same stream when new data is pushed from Twitter?

Thanks so much for any help anyone can offer. I have been hacking at this for hours but with no exception I am not sure what i am doing wrong.

Code: Select all
if (!mStreamingStarted) {
       
        try {
           
            console() << "Starting Twitter User Stream\n";
           
            const Poco::Net::Context::Ptr context( new Poco::Net::Context( Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE) );
           
            string text = "Buffering ...";
            Poco::URI uri("https://userstream.twitter.com/1.1/user.json");
            string path(uri.getPathAndQuery());
            if (path.empty()) path = "/";
            //Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort(), context);
            Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
            Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1);
            req.set("Authorization", createHeader() );
            req.setContentType("application/x-www-form-urlencoded");
            req.setKeepAlive(true);
            session.sendRequest(req);
           
            Poco::Net::HTTPResponse res;
            istream &is = session.receiveResponse(res);
            Poco::StreamCopier::copyToString(is, text);
           
            console() << text << "\n";
           
        } catch (Poco::Exception& exc) {
            std::cout << "Poco exception caught while attempting to connect." << std::endl;
            std::cerr << exc.displayText() << std::endl;
        }
    }


for reference this is the initial output I get when I first start a stream in terminal (a list of friend IDs) so I know I should get some response.

Code: Select all
{"friends":[115481492,16228965,53565454,129631339,221491262,325693974,123728038,115260611,22046488,389604028,20677866,22998193,12087912,164743595,28180275,1250116735,2991281,158878460,14380967,14873555,17679977,60625766,588732358,15456328,775742,6253282,373148698,277574049,205286266,23962323,29762189,17897698,485990080,13982132,493506710,21796025,14180709,115725928,252756514,5125971,97690334,16529656,21077230,510633179,107460558,17067603,248734611,19234098,469472838,28583197,28352713,202341554,224781889,104834365,551922437,62267325,1347494466,21373512,16739814,268830386,430192149,6490642,17637238,7252562,78208471,156836120,16246521,15112070,620311801,18396706,23494342,13218142,52789379,15234407,42087256,115492066,15235629,17472333,17005193,77463667,626750670,14848804,19448989,8963722,17136315,14587429,140233735,129542656,13095962,370741905,417486217,126336400,76388641,35682641,400299147,17093617,252755230,940520396,35196648,17404876,15057943,14384587,25097818,22032304,284995285,21171455,166571107,245430058,226655043,19038223,259716338,16709304,51788396,110866649,87591220,119477487,238848438,33582076,162441059,194196810]}
PlumCantaloupe
 
Posts: 1
Joined: 07 Aug 2013, 23:10

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest