how to get media related info using twitter4j

前端 未结 2 1079
野趣味
野趣味 2021-02-06 19:32

I am new to twitter4j. How i can get media related info using twitter4j library? I want to get info about photos,videos and article summary present in tweet.Thanks in advance.Is

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 20:22

    Yes Status#getMediaEntities() is what you want but you can only get basic information about the media contained in the Tweet. For example if you wanted to search for Tweets matching a criteria and get media entities' types and URLs you could do:

    Twitter twitter = TwitterFactory.getSingleton();
    Query query = new Query("...");
    QueryResult result = twitter.search(query);
    for (Status status : result.getTweets()) {
        for (MediaEntity mediaEntity : status.getMediaEntities()) {
            System.out.println(mediaEntity.getType() + ": " + mediaEntity.getMediaURL());
        }
    }
    

    There are other methods of retrieving Tweets using Twitter4J, e.g. using the Streaming API, take a look at the code examples on the Twitter4J web site for more information.

提交回复
热议问题