简体   繁体   English

如何使用twitter4j获取与媒体相关的信息

[英]how to get media related info using twitter4j

I am new to twitter4j. 我是twitter4j的新手。 How i can get media related info using twitter4j library? 我如何使用twitter4j库获取与媒体相关的信息? 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? 我想获取有关tweet中存在的照片,视频和文章摘要的信息。在此先感谢。getMediaEntities()方法是否足以满足此目的?

Yes Status#getMediaEntities() is what you want but you can only get basic information about the media contained in the Tweet. 是的Status#getMediaEntities()是您想要的,但是您只能获取有关Tweet中包含的媒体的基本信息。 For example if you wanted to search for Tweets matching a criteria and get media entities' types and URLs you could do: 例如,如果您要搜索符合条件的推文并获取媒体实体的类型和URL,则可以执行以下操作:

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, eg using the Streaming API, take a look at the code examples on the Twitter4J web site for more information. 还有其他使用Twitter4J检索推文的方法,例如使用Streaming API,请查看Twitter4J网站上的代码示例以获取更多信息。

Try hitting this request: 尝试达到以下要求:

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

Then, look for any media_url elements; 然后,查找所有media_url元素; those will contain the URL to any photos. 这些将包含任何照片的URL。 It may contain video links, so you'll have to filter for common image types (.png/.jpg/.gif/etc). 它可能包含视频链接,因此您必须过滤常见的图像类型(.png / .jpg / .gif / etc)。

Check this as well: https://dev.twitter.com/docs/tweet-entities 也请检查一下: https : //dev.twitter.com/docs/tweet-entities

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM