SlideShare uma empresa Scribd logo
1 de 28
Linked Data &
Semantic Web
Technology
Development of
Twitter Applications
Part 4. Timeline and Tweet
Dr. Myungjin Lee
Linked Data & Semantic Web Technology
Timeline
• Home Timeline
– a long stream showing all Tweets from those you have
chosen to follow on Twitter
home timeline
2
Linked Data & Semantic Web Technology
Timeline
user timeline
mentions timeline
retweets of me
3
Linked Data & Semantic Web Technology
REST API related to Timeline
• Timelines
– Timelines are collections of Tweets, ordered with the
most recent first.
Resource Description
GET
statuses/mentions_timeline
Returns the 20 most recent mentions (tweets
containing a users's @screen_name) for the
authenticating user
GET
statuses/user_timeline
Returns a collection of the most recent Tweets
posted by the user indicated by the screen_name or
user_id parameters
GET
statuses/home_timeline
Returns a collection of the most recent Tweets and
retweets posted by the authenticating user and the
users they follow
GET
statuses/retweets_of_me
Returns the most recent tweets authored by the
authenticating user that have been retweeted by
others
4
Linked Data & Semantic Web Technology
Responses of Timeline REST API
1. [
2. {
3. "created_at": "Mon Mar 25 08:47:46 +0000 2013",
4. "id": 316109141032714240,
5. "id_str": "316109141032714240",
6. "text": "RT @wonsoonpark: 이 협동조합국제회의에는 ...",
7. "source": "web",
8. "truncated": false,
9. "in_reply_to_status_id": null,
10. "in_reply_to_status_id_str": null,
11. "in_reply_to_user_id": null,
12. "in_reply_to_user_id_str": null,
13. "in_reply_to_screen_name": null,
14. "user": {
15. "id": 92297124,
16. "id_str": "92297124"
17. },
18. "geo": null,
19. "coordinates": null,
20. "place": null,
21. "contributors": null,
22. "retweeted_status": {
23. ... skip ...
24. },
25. "retweet_count": 27,
26. "favorite_count": 0,
27. "entities": {
28. "hashtags": [],
29. "urls": [],
30. "user_mentions": [
31. {
32. "screen_name": "wonsoonpark",
33. "name": "박원순",
34. "id": 76295962,
35. "id_str": "76295962",
36. "indices": [
37. 3,
38. 15
39. ]
40. }
41. ]
42. },
43. "favorited": false,
44. "retweeted": false,
45. "lang": "ko"
46. }
47. ]
5
Linked Data & Semantic Web Technology
Tweets Primary Field Guide
6
Field Type Description
coordinates Coordinates
Nullable. Represents the geographic location of this
Tweet as reported by the user or client application.
created_at String UTC time when this Tweet was created.
entities Entities
Entities which have been parsed out of the text of the
Tweet.
favorite_count Integer
Nullable. Indicates approximately how many times this
Tweet has been "favorited" by Twitter users.
id Int64
The integer representation of the unique identifier for this
Tweet.
id_str String
The string representation of the unique identifier for this
Tweet.
in_reply_to_screen_name String
Nullable. If the represented Tweet is a reply, this field will
contain the screen name of the original Tweet's author.
in_reply_to_status_id_str String
Nullable. If the represented Tweet is a reply, this field will
contain the string representation of the original Tweet's
ID.
in_reply_to_user_id_str String
Nullable. If the represented Tweet is a reply, this field will
contain the string representation of the original Tweet's
author ID.
place Places
Nullable. When present, indicates that the tweet is
associated a Place.
retweet_count Int Number of times this Tweet has been retweeted.
text String The actual UTF-8 text of the status update.
user Users The user who posted this Tweet.
Linked Data & Semantic Web Technology
Twitter4J Classes for Timeline API
• TimelinesResources Interface
– interface to support REST API related to timeline
– Methods
• ResponseList<Status> getHomeTimeline()
• ResponseList<Status> getHomeTimeline(Paging paging)
• ResponseList<Status> getMentionsTimeline()
• ResponseList<Status> getMentionsTimeline(Paging paging)
• ResponseList<Status> getRetweetsOfMe()
• ResponseList<Status> getRetweetsOfMe(Paging paging)
• ResponseList<Status> getUserTimeline()
• ResponseList<Status> getUserTimeline(Paging paging)
• ResponseList<Status> getUserTimeline(long userId)
• ResponseList<Status> getUserTimeline(java.lang.String screenName)
• Paging Class
– controls pagination
– Constructors
• Paging(int page, int count, long sinceId, long maxId)
• ResponseList<T> Interface
– list of Twitter Response
• Status Interface
– a data interface representing one single status of a user
– Methods
• java.util.Date getCreatedAt()
• long getId()
• Status getRetweetedStatus()
• java.lang.String getText()
• User getUser()
7
Linked Data & Semantic Web Technology
GET statuses/home_timeline
• Resource URL
– https://api.twitter.com/1.1/statuses/home_timeline.json
• Parameters
• Other Information
– Requests per rate limit window: 15/user
– Authentication: Requires user context
– Response Object: Tweets
– API Version: v1.1
count
optional
Specifies the number of records to retrieve. Must be less than or equal
to 200. Defaults to 20.
since_id
optional
Returns results with an ID greater than (that is, more recent than) the
specified ID. There are limits to the number of Tweets which can be
accessed through the API. If the limit of Tweets has occured since the
since_id, the since_id will be forced to the oldest ID available.
max_id
optional
Returns results with an ID less than (that is, older than) or equal to the
specified ID.
trim_user
optional
When set to either true, t or 1, each tweet returned in a timeline will
include a user object including only the status authors numerical ID.
Omit this parameter to receive the complete user object.
exclude_replies
optional
This parameter will prevent replies from appearing in the returned
timeline. Using exclude_replies with the count parameter will mean
you will receive up-to count tweets — this is because the count
parameter retrieves that many tweets before filtering out retweets and
replies.
contributor_details
optional
This parameter enhances the contributors element of the status
response to include the screen_name of the contributor. By default
only the user_id of the contributor is included.
include_entities
optional
The entities node will be disincluded when set to false.
8
Linked Data & Semantic Web Technology
Getting Home Timeline
1. import java.util.List;
2. import twitter4j.Twitter;
3. import twitter4j.TwitterException;
4. import twitter4j.TwitterFactory;
5. import twitter4j.Status;
6. public class TwitterTimeline {
7. Twitter twitter = null;
8. public TwitterTimeline() {
9. this.twitter = TwitterFactory.getSingleton();
10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey,
11. TwitterAccessToken.consumerSecret);
12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken());
13. }
14. public static void main(String args[]) throws TwitterException {
15. TwitterTimeline tt = new TwitterTimeline();
16. List<Status> tweets = tt.twitter.getHomeTimeline();
17. for (int i = 0; i < tweets.size(); i++) {
18. Status tweet = tweets.get(i);
19. System.out.println("tweet: " + tweet.getText());
20. }
21. }
22. }
9
Linked Data & Semantic Web Technology
Setting Pagination
• Constructors of Paging Class
– Paging()
– Paging(int page)
– Paging(int page, int count)
– Paging(int page, int count, long sinceId)
– Paging(int page, int count, long sinceId, long maxId)
– Paging(int page, long sinceId)
– Paging(long sinceId)
1. public static void main(String args[]) throws TwitterException {
2. TwitterTimeline tt = new TwitterTimeline();
3. List<Status> tweets = tt.twitter.getHomeTimeline(new Paging(1, 5));
4. for (int i = 0; i < tweets.size(); i++) {
5. Status tweet = tweets.get(i);
6. System.out.println("tweet: " + tweet.getText());
7. }
8. }
9. private List<Status> getHomeTimeline() throws TwitterException {
10. return this.twitter.getHomeTimeline();
11. }
10
Linked Data & Semantic Web Technology
Getting Status of Tweets
1. public static void main(String args[]) throws TwitterException {
2. TwitterTimeline tt = new TwitterTimeline();
3. List<Status> tweets = tt.twitter.getHomeTimeline();
4. for (int i = 0; i < tweets.size(); i++) {
5. Status tweet = tweets.get(i);
6. System.out.println(i + " tweet:");
7. System.out.println("tcreated at: " + tweet.getCreatedAt());
8. System.out.println("tid: " + tweet.getId());
9. System.out.println("tretweet count: " + tweet.getRetweetCount());
10. System.out.println("ttext: " + tweet.getText());
11. System.out.println("tuser: " + tweet.getUser());
12. }
13. }
11
Linked Data & Semantic Web Technology
GET statuses/user_timeline
• Resource URL
– https://api.twitter.com/1.1/statuses/user_timeline.json
• Parameters
• Other Information
– Requests per rate limit window: 180/user, 300/app
– Authentication: Required
– Response Object: Tweets
– API Version: v1.1
user_id
optional
The ID of the user for whom to return results for.
screen_name
optional
The screen name of the user for whom to return results for.
count
optional
Specifies the number of records to retrieve. Must be less than or equal to 200. Defaults to
20.
since_id
optional
Returns results with an ID greater than (that is, more recent than) the specified ID. There
are limits to the number of Tweets which can be accessed through the API. If the limit of
Tweets has occured since the since_id, the since_id will be forced to the oldest ID
available.
max_id
optional
Returns results with an ID less than (that is, older than) or equal to the specified ID.
trim_user
optional
When set to either true, t or 1, each tweet returned in a timeline will include a user object
including only the status authors numerical ID. Omit this parameter to receive the
complete user object.
exclude_replies
optional
This parameter will prevent replies from appearing in the returned timeline. Using
exclude_replies with the count parameter will mean you will receive up-to count tweets —
this is because the count parameter retrieves that many tweets before filtering out retweets
and replies.
contributor_details
optional
This parameter enhances the contributors element of the status response to include the
screen_name of the contributor. By default only the user_id of the contributor is included.
include_rts
optional
When set to false, the timeline will strip any native retweets (though they will still count
toward both the maximal length of the timeline and the slice selected by the count
parameter). Note: If you're using the trim_user parameter in conjunction with include_rts,
the retweets will still contain a full user object.
12
Linked Data & Semantic Web Technology
Getting User Timeline
1. public static void main(String args[]) throws TwitterException {
2. TwitterTimeline tt = new TwitterTimeline();
3. List<Status> tweets = tt.twitter.getUserTimeline(92297124);
4. // List<Status> tweets = tt.twitter.getUserTimeline("linked_data");
5. for (int i = 0; i < tweets.size(); i++) {
6. Status tweet = tweets.get(i);
7. System.out.println("text: " + tweet.getText());
8. }
9. }
13
Linked Data & Semantic Web Technology
GET statuses/mentions_timeline
• Resource URL
– https://api.twitter.com/1.1/statuses/mentions_timeline.json
• Parameters
• Other Information
– Requests per rate limit window: 15/user
– Authentication: Requires user context
– Response Object: Tweets
– API Version: v1.1
count
optional
Specifies the number of records to retrieve. Must be less than or equal
to 200. Defaults to 20.
since_id
optional
Returns results with an ID greater than (that is, more recent than) the
specified ID. There are limits to the number of Tweets which can be
accessed through the API. If the limit of Tweets has occured since the
since_id, the since_id will be forced to the oldest ID available.
max_id
optional
Returns results with an ID less than (that is, older than) or equal to the
specified ID.
trim_user
optional
When set to either true, t or 1, each tweet returned in a timeline will
include a user object including only the status authors numerical ID.
Omit this parameter to receive the complete user object.
contributor_details
optional
This parameter enhances the contributors element of the status
response to include the screen_name of the contributor. By default
only the user_id of the contributor is included.
include_entities
optional
The entities node will be disincluded when set to false.
14
Linked Data & Semantic Web Technology
GET statuses/retweet_of_me
• Resource URL
– https://api.twitter.com/1.1/statuses/retweets_of_me.json
• Parameters
• Other Information
– Requests per rate limit window: 15/user
– Authentication: Requires user context
– Response Object: Tweets
– API Version: v1.1
count
optional
Specifies the number of records to retrieve. Must be less than or equal
to 200. Defaults to 20.
since_id
optional
Returns results with an ID greater than (that is, more recent than) the
specified ID. There are limits to the number of Tweets which can be
accessed through the API. If the limit of Tweets has occured since the
since_id, the since_id will be forced to the oldest ID available.
max_id
optional
Returns results with an ID less than (that is, older than) or equal to the
specified ID.
trim_user
optional
When set to either true, t or 1, each tweet returned in a timeline will
include a user object including only the status authors numerical ID.
Omit this parameter to receive the complete user object.
include_entities
optional
The entities node will be disincluded when set to false.
include_user_entities
optional
The user entities node will be disincluded when set to false
15
Linked Data & Semantic Web Technology
Mentions Timeline and Retweets
1. public static void main(String args[]) throws TwitterException {
2. TwitterTimeline tt = new TwitterTimeline();
3. // List<Status> tweets = tt.twitter.getMentionsTimeline();
4. List<Status> tweets = tt.twitter.getRetweetsOfMe();
5. for (int i = 0; i < tweets.size(); i++) {
6. Status tweet = tweets.get(i);
7. System.out.println("text: " + tweet.getText());
8. }
9. }
16
Linked Data & Semantic Web Technology
Tweets
• What is tweets?
– the atomic building blocks of Twitter
– 140-character status updates with additional
associated metadata
– for a variety of reasons about a multitude of topics
tweet
retweets count
retweet
17
Linked Data & Semantic Web Technology
REST API related to Tweets
18
Resource Description
GET
statuses/retweets/:id
Returns up to 100 of the first retweets of a given tweet.
GET
statuses/show/:id
Returns a single Tweet, specified by the id parameter. The
Tweet's author will also be embedded within the tweet. See
Embeddable Timelines, Embeddable Tweets, and GET
statuses/oembed for tools to render Tweets according to
Display Requirements.
Linked Data & Semantic Web Technology
Twitter4J Classes for Tweet
• TweetsResources Interface
– Methods
• ResponseList<Status> getRetweets(long statusId)
• Status retweetStatus(long statusId)
• Status showStatus(long id)
19
Linked Data & Semantic Web Technology
GET statuses/show/:id
• Resource URL
– https://api.twitter.com/1.1/statuses/show.json
• Parameters
• Other Information
– Requests per rate limit window: 180/user, 180/app
– Authentication: Required
– Response Object: Tweets
– API Version: v1.1
id
required
The numerical ID of the desired Tweet.
trim_user
optional
When set to either true, t or 1, each tweet returned in a timeline will
include a user object including only the status authors numerical ID.
Omit this parameter to receive the complete user object.
include_my_retweet
optional
When set to either true, t or 1, any Tweets returned that have been
retweeted by the authenticating user will include an additional
current_user_retweet node, containing the ID of the source status for
the retweet.
include_entities
optional
The entities node will be disincluded when set to false.
20
Linked Data & Semantic Web Technology
Getting the Tweet
1. import java.util.List;
2. import twitter4j.Status;
3. import twitter4j.Twitter;
4. import twitter4j.TwitterException;
5. import twitter4j.TwitterFactory;
6. public class TwitterTweet {
7. Twitter twitter = null;
8. public TwitterTweet() {
9. this.twitter = TwitterFactory.getSingleton();
10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey,
11. TwitterAccessToken.consumerSecret);
12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken());
13. }
14. public static void main(String args[]) throws TwitterException {
15. TwitterTweet tt = new TwitterTweet();
16. Status status = tt.twitter.showStatus(Long.parseLong("319908547800481792"));
17. System.out.println("text: " + status.getText());
18. }
19. }
21
Linked Data & Semantic Web Technology
GET statuses/retweets/:id
• Resource URL
– https://api.twitter.com/1.1/statuses/retweets/:id.json
• Parameters
• Other Information
– Requests per rate limit window: 15/user, 60/app
– Authentication: Required
– Response Object: Tweets
– API Version: v1.1
id
required
The numerical ID of the desired status.
count
optional
Specifies the number of records to retrieve. Must be less than or equal to
100.
trim_user
optional
When set to either true, t or 1, each tweet returned in a timeline will include
a user object including only the status authors numerical ID. Omit this
parameter to receive the complete user object.
22
Linked Data & Semantic Web Technology
Getting Retweets
1. import java.util.List;
2. import twitter4j.Status;
3. import twitter4j.Twitter;
4. import twitter4j.TwitterException;
5. import twitter4j.TwitterFactory;
6. public class TwitterTweet {
7. Twitter twitter = null;
8. public TwitterTweet() {
9. this.twitter = TwitterFactory.getSingleton();
10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey,
11. TwitterAccessToken.consumerSecret);
12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken());
13. }
14. public static void main(String args[]) throws TwitterException {
15. TwitterTweet tt = new TwitterTweet();
16. List<Status> list = tt.twitter.getRetweets(Long
17. .parseLong("319908547800481792"));
18. for (int i = 0; i < list.size(); i++) {
19. Status status = list.get(i);
20. System.out.println("retweet user: " + status.getUser().getName());
21. }
22. }
23. }
23
Linked Data & Semantic Web Technology
Tweet’s Entities
• Entities
– to provide metadata and additional contextual
information about content posted on Twitter
• Types of Entity
– hashtags
• Represents hashtags which have been parsed out of the
Tweet text
– media
• Represents media elements uploaded with the Tweet
– urls
• Represents URLs included in the text of a Tweet or
within textual fields of a user object
– user mentions
• Represents other Twitter users mentioned in the text of
the Tweet
24
Linked Data & Semantic Web Technology
Entities’ Field Guide
• Hashtag
• Media
25
Field Type Description
indices Array of Int
An array of integers indicating the offsets within the Tweet text where
the hashtag begins and ends.
text String Name of the hashtag, minus the leading '#' character.
Field Type Description
display_url String URL of the media to display to clients.
expanded_url String
An expanded version of display_url. Links to the media display
page.
id Int64 ID of the media expressed as a 64-bit integer.
id_str String ID of the media expressed as a string.
indices
Array of
Int
An array of integers indicating the offsets within the Tweet text
where the URL begins and ends.
media_url String An http:// URL pointing directly to the uploaded media file.
media_url_https String
An https:// URL pointing directly to the uploaded media file, for
embedding on https pages.
sizes Object An object showing available sizes for the media file.
source_status_id Int64
For Tweets containing media that was originally associated with a
different tweet, this ID points to the original Tweet.
source_status_id_str Int64
For Tweets containing media that was originally associated with a
different tweet, this string-based ID points to the original Tweet.
type String Type of uploaded media.
url String Wrapped URL for the media link.
Linked Data & Semantic Web Technology
Entities’ Field Guide
• URL
• User Mention
26
Field Type Description
display_url String Version of the URL to display to clients.
expanded_url String Expanded version of display_url.
indices Array of Int
An array of integers representing offsets within the Tweet text where t
he URL begins and ends.
url String
Wrapped URL, corresponding to the value embedded directly into the
raw Tweet text, and the values for the indices parameter.
Field Type Description
id Int64 ID of the mentioned user, as an integer.
id_str String If of the mentioned user, as a string.
indices
Array of
Int
An array of integers representing the offsets within the Tweet text w
here the user reference begins and ends.
name String Display name of the referenced user.
screen_name String Screen name of the referenced user.
Linked Data & Semantic Web Technology
Twitter4J Classes for Entities
• Status Interface
– Methods
• HashtagEntity[] getHashtagEntities()
• MediaEntity[] getMediaEntities()
• URLEntity[] getURLEntities()
• UserMentionEntity[] getUserMentionEntities()
• HashtagEntity Interface
– A data interface representing one single Hashtag entity
– Methods
• String getText()
• MediaEntity Interface
– Methods
• long getId()
• String getMediaURL()
• String getType()
• URLEntity Interface
– A data interface representing one single URL entity.
– Methods
• String getDisplayURL()
• String getExpandedURL()
• String getURL()
• UserMentionEntity Interface
– A data interface representing one single user mention entity.
– Methods
• long getId()
• String getScreenName()
27
Linked Data & Semantic Web Technology
Getting Entities
1. public static void main(String args[]) throws TwitterException {
2. TwitterTweet tt = new TwitterTweet();
3. List<Status> tweets = tt.twitter.getHomeTimeline();
4. for (int i = 0; i < tweets.size(); i++) {
5. Status tweet = tweets.get(i);
6. System.out.println("tweet id: " + tweet.getId());
7. if(tweet.getHashtagEntities().length != 0) {
8. System.out.println("thastags:");
9. HashtagEntity[] hes = tweet.getHashtagEntities();
10. for(int j = 0; j < hes.length; j++) {
11. System.out.println("tt" + hes[j].getText());
12. }
13. }
14. if(tweet.getMediaEntities().length != 0) {
15. System.out.println("tmedia:");
16. MediaEntity[] mes = tweet.getMediaEntities();
17. for(int j = 0; j < mes.length; j++) {
18. System.out.println("tt" + mes[j].getType() + ", " + mes[j].getMediaURL());
19. }
20. }
21. if(tweet.getURLEntities().length != 0) {
22. System.out.println("tURLs:");
23. URLEntity[] urls = tweet.getURLEntities();
24. for(int j = 0; j < urls.length; j++) {
25. System.out.println("tt" + urls[j].getExpandedURL());
26. }
27. }
28. if(tweet.getUserMentionEntities().length != 0) {
29. System.out.println("tmentions:");
30. UserMentionEntity[] umes = tweet.getUserMentionEntities();
31. for(int j = 0; j < umes.length; j++) {
32. System.out.println("tt" + umes[j].getScreenName());
33. }
34. }
35. }
36. }
28

Mais conteúdo relacionado

Semelhante a Development of Twitter Application #4 - Timeline and Tweet

Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
ikailan
 

Semelhante a Development of Twitter Application #4 - Timeline and Tweet (20)

Development of Twitter Application #3 - OAuth
Development of Twitter Application #3 - OAuthDevelopment of Twitter Application #3 - OAuth
Development of Twitter Application #3 - OAuth
 
Social Aggregator Paper
Social Aggregator PaperSocial Aggregator Paper
Social Aggregator Paper
 
Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
 
SCWCD : The servlet model CHAP : 2
SCWCD : The servlet model CHAP : 2SCWCD : The servlet model CHAP : 2
SCWCD : The servlet model CHAP : 2
 
Social media analysis in R using twitter API
Social media analysis in R using twitter API Social media analysis in R using twitter API
Social media analysis in R using twitter API
 
SCWCD : The servlet model : CHAP : 2
SCWCD  : The servlet model : CHAP : 2SCWCD  : The servlet model : CHAP : 2
SCWCD : The servlet model : CHAP : 2
 
Servlet session 9
Servlet   session 9Servlet   session 9
Servlet session 9
 
Collect twitter data using python
Collect twitter data using pythonCollect twitter data using python
Collect twitter data using python
 
Collect twitter data using python
Collect twitter data using pythonCollect twitter data using python
Collect twitter data using python
 
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
.NET Fest 2018. Антон Молдован. One year of using F# in production at SBTech
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Development of Twitter Application #7 - Search
Development of Twitter Application #7 - SearchDevelopment of Twitter Application #7 - Search
Development of Twitter Application #7 - Search
 
Five steps to get tweets sent by a list of users
Five steps to get tweets sent by a list of usersFive steps to get tweets sent by a list of users
Five steps to get tweets sent by a list of users
 
Show loader to open url in web view
Show loader to open url in web viewShow loader to open url in web view
Show loader to open url in web view
 
Five steps to search and store tweets by keywords
Five steps to search and store tweets by keywordsFive steps to search and store tweets by keywords
Five steps to search and store tweets by keywords
 
Data annotation validation (ASP.net)
Data annotation validation (ASP.net)Data annotation validation (ASP.net)
Data annotation validation (ASP.net)
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
C*ollege Credit: Data Modeling for Apache Cassandra
C*ollege Credit: Data Modeling for Apache CassandraC*ollege Credit: Data Modeling for Apache Cassandra
C*ollege Credit: Data Modeling for Apache Cassandra
 
Reactive clean architecture
Reactive clean architectureReactive clean architecture
Reactive clean architecture
 

Mais de Myungjin Lee

Mais de Myungjin Lee (20)

지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSP
 
JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
 
JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍
 
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
 
오픈 데이터와 인공지능
오픈 데이터와 인공지능오픈 데이터와 인공지능
오픈 데이터와 인공지능
 
법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색
 
도서관과 Linked Data
도서관과 Linked Data도서관과 Linked Data
도서관과 Linked Data
 
공공데이터, 현재 우리는?
공공데이터, 현재 우리는?공공데이터, 현재 우리는?
공공데이터, 현재 우리는?
 
LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data Workshop
 
Introduction of Deep Learning
Introduction of Deep LearningIntroduction of Deep Learning
Introduction of Deep Learning
 
쉽게 이해하는 LOD
쉽게 이해하는 LOD쉽게 이해하는 LOD
쉽게 이해하는 LOD
 
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
 
LOD(Linked Open Data) Recommendations
LOD(Linked Open Data) RecommendationsLOD(Linked Open Data) Recommendations
LOD(Linked Open Data) Recommendations
 
Interlinking for Linked Data
Interlinking for Linked DataInterlinking for Linked Data
Interlinking for Linked Data
 
Linked Open Data Tutorial
Linked Open Data TutorialLinked Open Data Tutorial
Linked Open Data Tutorial
 
Linked Data Usecases
Linked Data UsecasesLinked Data Usecases
Linked Data Usecases
 
공공데이터와 Linked open data
공공데이터와 Linked open data공공데이터와 Linked open data
공공데이터와 Linked open data
 

Último

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

Development of Twitter Application #4 - Timeline and Tweet

  • 1. Linked Data & Semantic Web Technology Development of Twitter Applications Part 4. Timeline and Tweet Dr. Myungjin Lee
  • 2. Linked Data & Semantic Web Technology Timeline • Home Timeline – a long stream showing all Tweets from those you have chosen to follow on Twitter home timeline 2
  • 3. Linked Data & Semantic Web Technology Timeline user timeline mentions timeline retweets of me 3
  • 4. Linked Data & Semantic Web Technology REST API related to Timeline • Timelines – Timelines are collections of Tweets, ordered with the most recent first. Resource Description GET statuses/mentions_timeline Returns the 20 most recent mentions (tweets containing a users's @screen_name) for the authenticating user GET statuses/user_timeline Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters GET statuses/home_timeline Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow GET statuses/retweets_of_me Returns the most recent tweets authored by the authenticating user that have been retweeted by others 4
  • 5. Linked Data & Semantic Web Technology Responses of Timeline REST API 1. [ 2. { 3. "created_at": "Mon Mar 25 08:47:46 +0000 2013", 4. "id": 316109141032714240, 5. "id_str": "316109141032714240", 6. "text": "RT @wonsoonpark: 이 협동조합국제회의에는 ...", 7. "source": "web", 8. "truncated": false, 9. "in_reply_to_status_id": null, 10. "in_reply_to_status_id_str": null, 11. "in_reply_to_user_id": null, 12. "in_reply_to_user_id_str": null, 13. "in_reply_to_screen_name": null, 14. "user": { 15. "id": 92297124, 16. "id_str": "92297124" 17. }, 18. "geo": null, 19. "coordinates": null, 20. "place": null, 21. "contributors": null, 22. "retweeted_status": { 23. ... skip ... 24. }, 25. "retweet_count": 27, 26. "favorite_count": 0, 27. "entities": { 28. "hashtags": [], 29. "urls": [], 30. "user_mentions": [ 31. { 32. "screen_name": "wonsoonpark", 33. "name": "박원순", 34. "id": 76295962, 35. "id_str": "76295962", 36. "indices": [ 37. 3, 38. 15 39. ] 40. } 41. ] 42. }, 43. "favorited": false, 44. "retweeted": false, 45. "lang": "ko" 46. } 47. ] 5
  • 6. Linked Data & Semantic Web Technology Tweets Primary Field Guide 6 Field Type Description coordinates Coordinates Nullable. Represents the geographic location of this Tweet as reported by the user or client application. created_at String UTC time when this Tweet was created. entities Entities Entities which have been parsed out of the text of the Tweet. favorite_count Integer Nullable. Indicates approximately how many times this Tweet has been "favorited" by Twitter users. id Int64 The integer representation of the unique identifier for this Tweet. id_str String The string representation of the unique identifier for this Tweet. in_reply_to_screen_name String Nullable. If the represented Tweet is a reply, this field will contain the screen name of the original Tweet's author. in_reply_to_status_id_str String Nullable. If the represented Tweet is a reply, this field will contain the string representation of the original Tweet's ID. in_reply_to_user_id_str String Nullable. If the represented Tweet is a reply, this field will contain the string representation of the original Tweet's author ID. place Places Nullable. When present, indicates that the tweet is associated a Place. retweet_count Int Number of times this Tweet has been retweeted. text String The actual UTF-8 text of the status update. user Users The user who posted this Tweet.
  • 7. Linked Data & Semantic Web Technology Twitter4J Classes for Timeline API • TimelinesResources Interface – interface to support REST API related to timeline – Methods • ResponseList<Status> getHomeTimeline() • ResponseList<Status> getHomeTimeline(Paging paging) • ResponseList<Status> getMentionsTimeline() • ResponseList<Status> getMentionsTimeline(Paging paging) • ResponseList<Status> getRetweetsOfMe() • ResponseList<Status> getRetweetsOfMe(Paging paging) • ResponseList<Status> getUserTimeline() • ResponseList<Status> getUserTimeline(Paging paging) • ResponseList<Status> getUserTimeline(long userId) • ResponseList<Status> getUserTimeline(java.lang.String screenName) • Paging Class – controls pagination – Constructors • Paging(int page, int count, long sinceId, long maxId) • ResponseList<T> Interface – list of Twitter Response • Status Interface – a data interface representing one single status of a user – Methods • java.util.Date getCreatedAt() • long getId() • Status getRetweetedStatus() • java.lang.String getText() • User getUser() 7
  • 8. Linked Data & Semantic Web Technology GET statuses/home_timeline • Resource URL – https://api.twitter.com/1.1/statuses/home_timeline.json • Parameters • Other Information – Requests per rate limit window: 15/user – Authentication: Requires user context – Response Object: Tweets – API Version: v1.1 count optional Specifies the number of records to retrieve. Must be less than or equal to 200. Defaults to 20. since_id optional Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available. max_id optional Returns results with an ID less than (that is, older than) or equal to the specified ID. trim_user optional When set to either true, t or 1, each tweet returned in a timeline will include a user object including only the status authors numerical ID. Omit this parameter to receive the complete user object. exclude_replies optional This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many tweets before filtering out retweets and replies. contributor_details optional This parameter enhances the contributors element of the status response to include the screen_name of the contributor. By default only the user_id of the contributor is included. include_entities optional The entities node will be disincluded when set to false. 8
  • 9. Linked Data & Semantic Web Technology Getting Home Timeline 1. import java.util.List; 2. import twitter4j.Twitter; 3. import twitter4j.TwitterException; 4. import twitter4j.TwitterFactory; 5. import twitter4j.Status; 6. public class TwitterTimeline { 7. Twitter twitter = null; 8. public TwitterTimeline() { 9. this.twitter = TwitterFactory.getSingleton(); 10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey, 11. TwitterAccessToken.consumerSecret); 12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken()); 13. } 14. public static void main(String args[]) throws TwitterException { 15. TwitterTimeline tt = new TwitterTimeline(); 16. List<Status> tweets = tt.twitter.getHomeTimeline(); 17. for (int i = 0; i < tweets.size(); i++) { 18. Status tweet = tweets.get(i); 19. System.out.println("tweet: " + tweet.getText()); 20. } 21. } 22. } 9
  • 10. Linked Data & Semantic Web Technology Setting Pagination • Constructors of Paging Class – Paging() – Paging(int page) – Paging(int page, int count) – Paging(int page, int count, long sinceId) – Paging(int page, int count, long sinceId, long maxId) – Paging(int page, long sinceId) – Paging(long sinceId) 1. public static void main(String args[]) throws TwitterException { 2. TwitterTimeline tt = new TwitterTimeline(); 3. List<Status> tweets = tt.twitter.getHomeTimeline(new Paging(1, 5)); 4. for (int i = 0; i < tweets.size(); i++) { 5. Status tweet = tweets.get(i); 6. System.out.println("tweet: " + tweet.getText()); 7. } 8. } 9. private List<Status> getHomeTimeline() throws TwitterException { 10. return this.twitter.getHomeTimeline(); 11. } 10
  • 11. Linked Data & Semantic Web Technology Getting Status of Tweets 1. public static void main(String args[]) throws TwitterException { 2. TwitterTimeline tt = new TwitterTimeline(); 3. List<Status> tweets = tt.twitter.getHomeTimeline(); 4. for (int i = 0; i < tweets.size(); i++) { 5. Status tweet = tweets.get(i); 6. System.out.println(i + " tweet:"); 7. System.out.println("tcreated at: " + tweet.getCreatedAt()); 8. System.out.println("tid: " + tweet.getId()); 9. System.out.println("tretweet count: " + tweet.getRetweetCount()); 10. System.out.println("ttext: " + tweet.getText()); 11. System.out.println("tuser: " + tweet.getUser()); 12. } 13. } 11
  • 12. Linked Data & Semantic Web Technology GET statuses/user_timeline • Resource URL – https://api.twitter.com/1.1/statuses/user_timeline.json • Parameters • Other Information – Requests per rate limit window: 180/user, 300/app – Authentication: Required – Response Object: Tweets – API Version: v1.1 user_id optional The ID of the user for whom to return results for. screen_name optional The screen name of the user for whom to return results for. count optional Specifies the number of records to retrieve. Must be less than or equal to 200. Defaults to 20. since_id optional Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available. max_id optional Returns results with an ID less than (that is, older than) or equal to the specified ID. trim_user optional When set to either true, t or 1, each tweet returned in a timeline will include a user object including only the status authors numerical ID. Omit this parameter to receive the complete user object. exclude_replies optional This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many tweets before filtering out retweets and replies. contributor_details optional This parameter enhances the contributors element of the status response to include the screen_name of the contributor. By default only the user_id of the contributor is included. include_rts optional When set to false, the timeline will strip any native retweets (though they will still count toward both the maximal length of the timeline and the slice selected by the count parameter). Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will still contain a full user object. 12
  • 13. Linked Data & Semantic Web Technology Getting User Timeline 1. public static void main(String args[]) throws TwitterException { 2. TwitterTimeline tt = new TwitterTimeline(); 3. List<Status> tweets = tt.twitter.getUserTimeline(92297124); 4. // List<Status> tweets = tt.twitter.getUserTimeline("linked_data"); 5. for (int i = 0; i < tweets.size(); i++) { 6. Status tweet = tweets.get(i); 7. System.out.println("text: " + tweet.getText()); 8. } 9. } 13
  • 14. Linked Data & Semantic Web Technology GET statuses/mentions_timeline • Resource URL – https://api.twitter.com/1.1/statuses/mentions_timeline.json • Parameters • Other Information – Requests per rate limit window: 15/user – Authentication: Requires user context – Response Object: Tweets – API Version: v1.1 count optional Specifies the number of records to retrieve. Must be less than or equal to 200. Defaults to 20. since_id optional Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available. max_id optional Returns results with an ID less than (that is, older than) or equal to the specified ID. trim_user optional When set to either true, t or 1, each tweet returned in a timeline will include a user object including only the status authors numerical ID. Omit this parameter to receive the complete user object. contributor_details optional This parameter enhances the contributors element of the status response to include the screen_name of the contributor. By default only the user_id of the contributor is included. include_entities optional The entities node will be disincluded when set to false. 14
  • 15. Linked Data & Semantic Web Technology GET statuses/retweet_of_me • Resource URL – https://api.twitter.com/1.1/statuses/retweets_of_me.json • Parameters • Other Information – Requests per rate limit window: 15/user – Authentication: Requires user context – Response Object: Tweets – API Version: v1.1 count optional Specifies the number of records to retrieve. Must be less than or equal to 200. Defaults to 20. since_id optional Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available. max_id optional Returns results with an ID less than (that is, older than) or equal to the specified ID. trim_user optional When set to either true, t or 1, each tweet returned in a timeline will include a user object including only the status authors numerical ID. Omit this parameter to receive the complete user object. include_entities optional The entities node will be disincluded when set to false. include_user_entities optional The user entities node will be disincluded when set to false 15
  • 16. Linked Data & Semantic Web Technology Mentions Timeline and Retweets 1. public static void main(String args[]) throws TwitterException { 2. TwitterTimeline tt = new TwitterTimeline(); 3. // List<Status> tweets = tt.twitter.getMentionsTimeline(); 4. List<Status> tweets = tt.twitter.getRetweetsOfMe(); 5. for (int i = 0; i < tweets.size(); i++) { 6. Status tweet = tweets.get(i); 7. System.out.println("text: " + tweet.getText()); 8. } 9. } 16
  • 17. Linked Data & Semantic Web Technology Tweets • What is tweets? – the atomic building blocks of Twitter – 140-character status updates with additional associated metadata – for a variety of reasons about a multitude of topics tweet retweets count retweet 17
  • 18. Linked Data & Semantic Web Technology REST API related to Tweets 18 Resource Description GET statuses/retweets/:id Returns up to 100 of the first retweets of a given tweet. GET statuses/show/:id Returns a single Tweet, specified by the id parameter. The Tweet's author will also be embedded within the tweet. See Embeddable Timelines, Embeddable Tweets, and GET statuses/oembed for tools to render Tweets according to Display Requirements.
  • 19. Linked Data & Semantic Web Technology Twitter4J Classes for Tweet • TweetsResources Interface – Methods • ResponseList<Status> getRetweets(long statusId) • Status retweetStatus(long statusId) • Status showStatus(long id) 19
  • 20. Linked Data & Semantic Web Technology GET statuses/show/:id • Resource URL – https://api.twitter.com/1.1/statuses/show.json • Parameters • Other Information – Requests per rate limit window: 180/user, 180/app – Authentication: Required – Response Object: Tweets – API Version: v1.1 id required The numerical ID of the desired Tweet. trim_user optional When set to either true, t or 1, each tweet returned in a timeline will include a user object including only the status authors numerical ID. Omit this parameter to receive the complete user object. include_my_retweet optional When set to either true, t or 1, any Tweets returned that have been retweeted by the authenticating user will include an additional current_user_retweet node, containing the ID of the source status for the retweet. include_entities optional The entities node will be disincluded when set to false. 20
  • 21. Linked Data & Semantic Web Technology Getting the Tweet 1. import java.util.List; 2. import twitter4j.Status; 3. import twitter4j.Twitter; 4. import twitter4j.TwitterException; 5. import twitter4j.TwitterFactory; 6. public class TwitterTweet { 7. Twitter twitter = null; 8. public TwitterTweet() { 9. this.twitter = TwitterFactory.getSingleton(); 10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey, 11. TwitterAccessToken.consumerSecret); 12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken()); 13. } 14. public static void main(String args[]) throws TwitterException { 15. TwitterTweet tt = new TwitterTweet(); 16. Status status = tt.twitter.showStatus(Long.parseLong("319908547800481792")); 17. System.out.println("text: " + status.getText()); 18. } 19. } 21
  • 22. Linked Data & Semantic Web Technology GET statuses/retweets/:id • Resource URL – https://api.twitter.com/1.1/statuses/retweets/:id.json • Parameters • Other Information – Requests per rate limit window: 15/user, 60/app – Authentication: Required – Response Object: Tweets – API Version: v1.1 id required The numerical ID of the desired status. count optional Specifies the number of records to retrieve. Must be less than or equal to 100. trim_user optional When set to either true, t or 1, each tweet returned in a timeline will include a user object including only the status authors numerical ID. Omit this parameter to receive the complete user object. 22
  • 23. Linked Data & Semantic Web Technology Getting Retweets 1. import java.util.List; 2. import twitter4j.Status; 3. import twitter4j.Twitter; 4. import twitter4j.TwitterException; 5. import twitter4j.TwitterFactory; 6. public class TwitterTweet { 7. Twitter twitter = null; 8. public TwitterTweet() { 9. this.twitter = TwitterFactory.getSingleton(); 10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey, 11. TwitterAccessToken.consumerSecret); 12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken()); 13. } 14. public static void main(String args[]) throws TwitterException { 15. TwitterTweet tt = new TwitterTweet(); 16. List<Status> list = tt.twitter.getRetweets(Long 17. .parseLong("319908547800481792")); 18. for (int i = 0; i < list.size(); i++) { 19. Status status = list.get(i); 20. System.out.println("retweet user: " + status.getUser().getName()); 21. } 22. } 23. } 23
  • 24. Linked Data & Semantic Web Technology Tweet’s Entities • Entities – to provide metadata and additional contextual information about content posted on Twitter • Types of Entity – hashtags • Represents hashtags which have been parsed out of the Tweet text – media • Represents media elements uploaded with the Tweet – urls • Represents URLs included in the text of a Tweet or within textual fields of a user object – user mentions • Represents other Twitter users mentioned in the text of the Tweet 24
  • 25. Linked Data & Semantic Web Technology Entities’ Field Guide • Hashtag • Media 25 Field Type Description indices Array of Int An array of integers indicating the offsets within the Tweet text where the hashtag begins and ends. text String Name of the hashtag, minus the leading '#' character. Field Type Description display_url String URL of the media to display to clients. expanded_url String An expanded version of display_url. Links to the media display page. id Int64 ID of the media expressed as a 64-bit integer. id_str String ID of the media expressed as a string. indices Array of Int An array of integers indicating the offsets within the Tweet text where the URL begins and ends. media_url String An http:// URL pointing directly to the uploaded media file. media_url_https String An https:// URL pointing directly to the uploaded media file, for embedding on https pages. sizes Object An object showing available sizes for the media file. source_status_id Int64 For Tweets containing media that was originally associated with a different tweet, this ID points to the original Tweet. source_status_id_str Int64 For Tweets containing media that was originally associated with a different tweet, this string-based ID points to the original Tweet. type String Type of uploaded media. url String Wrapped URL for the media link.
  • 26. Linked Data & Semantic Web Technology Entities’ Field Guide • URL • User Mention 26 Field Type Description display_url String Version of the URL to display to clients. expanded_url String Expanded version of display_url. indices Array of Int An array of integers representing offsets within the Tweet text where t he URL begins and ends. url String Wrapped URL, corresponding to the value embedded directly into the raw Tweet text, and the values for the indices parameter. Field Type Description id Int64 ID of the mentioned user, as an integer. id_str String If of the mentioned user, as a string. indices Array of Int An array of integers representing the offsets within the Tweet text w here the user reference begins and ends. name String Display name of the referenced user. screen_name String Screen name of the referenced user.
  • 27. Linked Data & Semantic Web Technology Twitter4J Classes for Entities • Status Interface – Methods • HashtagEntity[] getHashtagEntities() • MediaEntity[] getMediaEntities() • URLEntity[] getURLEntities() • UserMentionEntity[] getUserMentionEntities() • HashtagEntity Interface – A data interface representing one single Hashtag entity – Methods • String getText() • MediaEntity Interface – Methods • long getId() • String getMediaURL() • String getType() • URLEntity Interface – A data interface representing one single URL entity. – Methods • String getDisplayURL() • String getExpandedURL() • String getURL() • UserMentionEntity Interface – A data interface representing one single user mention entity. – Methods • long getId() • String getScreenName() 27
  • 28. Linked Data & Semantic Web Technology Getting Entities 1. public static void main(String args[]) throws TwitterException { 2. TwitterTweet tt = new TwitterTweet(); 3. List<Status> tweets = tt.twitter.getHomeTimeline(); 4. for (int i = 0; i < tweets.size(); i++) { 5. Status tweet = tweets.get(i); 6. System.out.println("tweet id: " + tweet.getId()); 7. if(tweet.getHashtagEntities().length != 0) { 8. System.out.println("thastags:"); 9. HashtagEntity[] hes = tweet.getHashtagEntities(); 10. for(int j = 0; j < hes.length; j++) { 11. System.out.println("tt" + hes[j].getText()); 12. } 13. } 14. if(tweet.getMediaEntities().length != 0) { 15. System.out.println("tmedia:"); 16. MediaEntity[] mes = tweet.getMediaEntities(); 17. for(int j = 0; j < mes.length; j++) { 18. System.out.println("tt" + mes[j].getType() + ", " + mes[j].getMediaURL()); 19. } 20. } 21. if(tweet.getURLEntities().length != 0) { 22. System.out.println("tURLs:"); 23. URLEntity[] urls = tweet.getURLEntities(); 24. for(int j = 0; j < urls.length; j++) { 25. System.out.println("tt" + urls[j].getExpandedURL()); 26. } 27. } 28. if(tweet.getUserMentionEntities().length != 0) { 29. System.out.println("tmentions:"); 30. UserMentionEntity[] umes = tweet.getUserMentionEntities(); 31. for(int j = 0; j < umes.length; j++) { 32. System.out.println("tt" + umes[j].getScreenName()); 33. } 34. } 35. } 36. } 28