Getting tweets with specific hashtag from a user&#

2019-04-15 05:25发布

I am trying to get tweets with specific hashtag from a user's timeline (ex- @kkajnabi#suman) using Fabric in android.

I am able to get tweets from %23suman(#suman) using below code. But i want to get tweets from %40kkajnabi%23suman(@kkajnabi#suman).

public class TimelineActivity extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.timeline);

        TwitterAuthConfig authConfig =  new TwitterAuthConfig("xxxxxxbbbbwdqddq", "eieuhquifhioqhfiohqoifhoi");
        Fabric.with((this), new TwitterCore(authConfig), new TweetUi());

        final SearchTimeline searchTimeline = new SearchTimeline.Builder()
                .query("%40kkajnabi%23suman")
                .build();

I think this approach is wrong . Anyone plz help me on writing query for %40kkajnabi%23suman or there is some other approach to do this.

1条回答
冷血范
2楼-- · 2019-04-15 05:48

It's a little rough, but here's how to get the user tweets

ArrayList<Tweet> tweets = new ArrayList<>();
TwitterCore.getInstance().getApiClient(session).getStatusesService()
    .userTimeline(null,
            "screenname",
            10 //the number of tweets we want to fetch,
            null,
            null,
            null,
            null,
            null,
            null,
            new Callback<List<Tweet>>() {
                @Override
                public void success(Result<List<Tweet>> result) {
                    for (Tweet t : result.data) {
                        tweets.add(t);
                        android.util.Log.d("twittercommunity", "tweet is " + t.text);
                    }
                }

                @Override
                public void failure(TwitterException exception) {
                    android.util.Log.d("twittercommunity", "exception " + exception);
                }
            });

Then what I would do, is a quick conditional to determine if the Tweet object contains the hashtags that you want from the entities attribute. I'll need to play with this a bit to give you the exact answer you need. I looked at the API, unfortunately there is no argument that I can find for getting a user's timeline and subsequently filtering by tag. So I think you'll need to iterate through. Here's a good reference to the userTimeline() method of the StatusesService class https://twittercommunity.com/t/android-usertimeline-question/30263/2

Again, I will update this answer when I have a chance later today

查看更多
登录 后发表回答