gusaindpk
gusaindpk

Reputation: 1253

how to get media related info using twitter4j

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 getMediaEntities() method is enough for this purpose?

Upvotes: 1

Views: 4396

Answers (2)

Jonathan
Jonathan

Reputation: 20385

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.

Upvotes: 8

Juned Ahsan
Juned Ahsan

Reputation: 68715

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

Upvotes: 1

Related Questions