how to get media related info using twitter4j

前端 未结 2 1078
野趣味
野趣味 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.

    0 讨论(0)
  • 2021-02-06 20:29

    Try hitting this request:

    https://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitter&include_entities=true

    Then, look for any media_url elements; those will contain the URL to any photos. It may contain video links, so you'll have to filter for common image types (.png/.jpg/.gif/etc).

    Check this as well: https://dev.twitter.com/docs/tweet-entities

    0 讨论(0)
提交回复
热议问题