Trying to use HTTPSClientSession for Twitter OAUTH

Please post support and help requests here.
Posts: 1
Joined: 07 Aug 2013, 23:10

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("");
            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() );
            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


Return to “Support”

Who is online

Users browsing this forum: thelifeofapanca and 1 guest