Search code examples
twitterapache-camelakkaakka-camel

Accessing Twitter with Akka Camel to return JSON


I was using an HTTP POST method using the URL "https://stream.twitter.com/1.1/statuses/filter.json" and in the body I was posting the key/value I wanted to get tweets from - for example "track=london". This was working fine.

Now I am trying to switch to AKKA-CAMEL and I am using their twitter consumer. I am using an endpoint URL of:

def endpointUri: String = s"twitter:////search?type=direct&keywords=${Settings.queryList()}&consumerKey=${tweeterCredentials.consumerKey}&consumerSecret=${tweeterCredentials.consumerSecret}&accessToken=${tweeterCredentials.accessToken}&accessTokenSecret=${tweeterCredentials.accessTokenSecret}"

I get a response from twitter but it is not in JSON and it is not the same information about the tweet as before. It just return the tweet text but before I was getting the whole metadata which I need to analyze.

Does somebody knows how to configure Camel URI to return JSON and the whole metadata as before?

Thanks


Solution

  • I got this to work by using the following syntax:

    def endpointUri: String = s"twitter://streaming/filter?type=event&keywords=${Settings.queryList()}&consumerKey=${tweeterCredentials.consumerKey}&consumerSecret=${tweeterCredentials.consumerSecret}&accessToken=${tweeterCredentials.accessToken}&accessTokenSecret=${tweeterCredentials.accessTokenSecret}"
    

    Where: Settings.queryList return a comma separated list of keyworkds. The object tweeterCredentials holds the keys from Tweeter to access the site.

    Also it is necessary to set autoAck like this in Camel:

    override def autoAck = true

    This prevents a timeout exception.