Twitter结构获得带有标签的推文

时间:2015-01-04 17:44:31

标签: android twitter twitter-fabric

如何使用twitter的面料sdk for android获取特定主题标签的推文?

当前文档仅显示按ID获取推文。

List<Long> tweetIds = Arrays.asList(503435417459249153L,510908133917487104L,
                                                                  473514864153870337L,
                                                                 477788140900347904L);
final TweetViewFetchAdapter adapter =
        new TweetViewFetchAdapter<CompactTweetView>(
                                        TweetListActivity.this);

2 个答案:

答案 0 :(得分:3)

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(SecretKet);
    User user;
    AccessToken newAcc = new AccessToken(getoken, getokensecret);
    Twitter twitter = new TwitterFactory(builder.build())
            .getInstance(newAcc);

    try {
        List<twitter4j.Status> statuslist = new ArrayList<twitter4j.Status>();
                    //23 for hash #
      Query AA = new Query("%23" + HASH_TAG_string);
        AA.setCount(20);
        //if (!statusid.equals("")) {
            //long l = Long.parseLong(statusid);
            //AA.setMaxId(l - 1);
        //}

        QueryResult result = twitter.search(AA);
        statuslist = result.getTweets();
        long id = result.getMaxId();

        System.out.println("Count : " + result.getTweets().size());

        mList = new ArrayList<GetterSetteList>();
        for (twitter4j.Status status : statuslist) {
            GetterSetteList obj = new GetterSetteList();
            String sts = status.getText();
            obj.setStatusID("" + status.getId());
            Log.d("STATE", sts);
            System.out.println("=======ID=====" + status.getId());

            User u = status.getUser();

            obj.setImageURL(u.getProfileImageURLHttps());
            obj.setmStatus(status.getText());
            Date date = status.getCreatedAt();
            obj.setStatustime(date.toString());

            obj.setUser_id(u.getScreenName());
            obj.setUsername(u.getName());
            mList.add(obj);

        }
        // user = twitter.showUser("jaswinderwadali");
        // System.out.println(user.getName());
    } catch (TwitterException e) {
        // TODO Auto-generated catch block
        flag = 1;
        Log.v("ERROR", "GetHastTagdata" + e.toString());
        e.printStackTrace();
    }

答案 1 :(得分:2)

在这一刻,它更容易。

import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class TimelineActivity extends ListActivity {

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

    final SearchTimeline searchTimeline = new SearchTimeline.Builder().query("#twitterflock").build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(this, searchTimeline);
    setListAdapter(adapter);
  }
}

问候