3

I have an application that makes it possible for users to add hashtags that will be followed on Twitter and also to follow other users if they have Twitter accounts registered on the application. These functionalities are implemented using twitter4j. However, since I'm redesigning application at the moment I wanted to improve it and implement using Apache Spark Twitter streaming, so I have two questions about it:

1) Is it possible to create filter with users twitter ids that I want to follow? 2) Since application makes it possible for end users to add new hashtags often, my current implementation has been implemented in such a way that each time new hashtag has been added, twitter stream has to be stopped and initialized again. Is there any more efficient way to add new hashtags without interrupting stream, or that is the only way to add new hashtag?

Thanks,

Zoran

zoran jeremic
  • 2,046
  • 4
  • 21
  • 47
  • 1
    There's quite a few SO answers for your questions, at least for number 2: no, there is no other way. (E.g. [this one](http://stackoverflow.com/questions/13561713/how-to-change-keywords-on-twitter-stream-api-using-twitter4j)). As for number 1, well it depends on your app, but from your description, I think the easier might be to use the [user endpoint](https://dev.twitter.com/streaming/reference/get/user). Hope it helps. – lrnzcig Jun 21 '15 at 15:48
  • Thanks for your answer. I was afraid there is no solution for 2. For the first question, I used Twitter4j version 4.0.1 earlier and it was possible to create FilterQuery with long[] of user ids you want to follow. Apache Spark Twitter Streaming uses Twitter4j version 3.0.3 for streaming, and I can't find how I can reach the same functionality. – zoran jeremic Jun 21 '15 at 23:29
  • Sorry, my previous comment for number (1) did not make much sense. Sure, if you are using `FilterQuery` then you use [this endpoint](https://dev.twitter.com/streaming/reference/post/statuses/filter), which has a parameter `follow`. However, I've checked version 3.0.3, and in there `FilterQuery` has less parameters, but `follow` is already there. Which method are you using? If you use `TwitterStream.filter` it should work. – lrnzcig Jun 22 '15 at 09:15
  • TwitterStream.filter works fine. I already have that long time ago. However, this approach uses twitter4j library directly. What I wanted is to use Apache Spark Twitter streaming. If you want to follow keywords, initialization of stream is straightforward: JavaDStream inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()), filters); However, org.apache.spark.streaming.twitter.TwitterUtils doesn't provide API for long[] filters, and I couldn't find any example or explanation having this implemented. – zoran jeremic Jun 22 '15 at 17:01

0 Answers0