• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Development of Twitter Application #5 - Users
 

Development of Twitter Application #5 - Users

on

  • 717 views

This series of slides describes how to develop a twitter application.

This series of slides describes how to develop a twitter application.
This slide describes how to get information about Twitter users using Twitter4J.

Statistics

Views

Total Views
717
Views on SlideShare
717
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Development of Twitter Application #5 - Users Development of Twitter Application #5 - Users Document Transcript

    • Linked Data &Semantic WebTechnologyDevelopment ofTwitter ApplicationsPart 5. UsersDr. Myungjin Lee
    • Linked Data & Semantic Web TechnologyUsers• Users in Twitter– anyone or anything who tweets, follows, createslists, has a home_timeline, can be mentioned, and canbe looked up in bulk2followers: anotherTwitter user who hasfollowed youfollowing (frineds): thequantity of other Twitter usersyou have chosen to followname: a name that can bedifferent from your username andis used to locate you on Twitterscree name (user name): unique andfewer than 15 characters to identify youon Twitter for replies and mentionslocation descriptionurlprofile image
    • Linked Data & Semantic Web TechnologyREST API related to Users3Resource DescriptionGETusers/lookupReturns fully-hydrated user objects for up to 100 users perrequest, as specified by comma-separated values passed tothe user_id and/or screen_name parameters. This method isespecially useful when used in conjunction with collectionsof user IDs returned from GET friends/ids and GETfollowers/...GETusers/showReturns a variety of information about the user specified bythe required user_id or screen_name parameter. Theauthors most recent Tweet will be returned inline whenpossible. GET users/lookup is used to retrieve a bulkcollection of user objects.GETusers/searchProvides a simple, relevance-based search interface topublic user accounts on Twitter. Try querying by topicalinterest, full name, company name, location, or othercriteria. Exact match searches are not supported. Only thefirst 1,000 matching results are available.
    • Linked Data & Semantic Web TechnologyUsers Primary Field Guide4Field Type Descriptioncreated_at String The UTC datetime that the user account was created on Twitterdescription String Nullable. The user-defined UTF-8 string describing their account.entities EntitiesEntities which have been parsed out of the url or description fieldsdefined by the user.favourites_count Int The number of tweets this user has favorited in the accounts lifetime.followers_count Int The number of followers this account currently has.friends_count IntThe number of users this account is following (AKA their"followings").id Int64 The integer representation of the unique identifier for this User.id_str String The string representation of the unique identifier for this Tweet.lang String The BCP 47 code for the users self-declared user interface language.listed_count Int The number of public lists that this user is a member of.location String Nullable. The user-defined location for this accounts profile.name String The name of the user, as theyve defined it.protected Boolean When true, indicates that this user has chosen to protect their Tweets.screen_name StringThe screen name, handle, or alias that this user identifies themselveswith.status Tweets Nullable. If possible, the users most recent tweet or retweet.statuses_count Int The number of tweets (including retweets) issued by the user.url StringNullable. A URL provided by the user in association with theirprofile.
    • Linked Data & Semantic Web TechnologyTwitter4J Classes for Users• UsersResources Interface– Methods• ResponseList<User> lookupUsers(long[] ids)• ResponseList<User> searchUsers(String query, int page)• User showUser(long userId)• User showUser(String screenName)• User Interface– A data interface representing Basic user informationelement– Methods• Date getCreatedAt()• String getDescription()• int getFavouritesCount()• int getFollowersCount()• int getFriendsCount()• long getId()• String getLang()• int getListedCount()• String getLocation()• String getName()• String getProfileImageURL()• String getScreenName()• int getStatusesCount()• String getURL()5
    • Linked Data & Semantic Web TechnologyGET users/show• Resource URL– http://api.twitter.com/1.1/users/show.json• Parameters• Other Information– Requests per rate limit window: 180/user, 180/app– Authentication: Required– Response Object: Users– API Version: v1.1user_idrequiredThe ID of the user for whom to return results for. Either an id orscreen_name is required for this method.screen_namerequiredThe screen name of the user for whom to return results for. Either a idor screen_name is required for this method.include_entitiesoptionalThe entities node will be disincluded when set to false.6
    • Linked Data & Semantic Web TechnologyGetting the User1. import java.util.List;2. import twitter4j.Twitter;3. import twitter4j.TwitterException;4. import twitter4j.TwitterFactory;5. import twitter4j.User;6. public class TwitterUser {7. Twitter twitter = null;8. public TwitterUser() {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. TwitterUser tt = new TwitterUser ();16. User user = tt.twitter.showUser("ACSpressroom");17. System.out.println(user.getId());18. System.out.println(user.getName());19. System.out.println(user.getScreenName());20. System.out.println(user.getDescription());21. System.out.println(user.getLocation());22. System.out.println(user.getURL());23. System.out.println(user.getProfileBackgroundImageURL());24. }25. }7
    • Linked Data & Semantic Web TechnologyGET users/lookup• Resource URL– https://api.twitter.com/1.1/users/lookup.json• Parameters• Other Information– Requests per rate limit window: 180/user, 60/app– Authentication: Required– Response Object: Users– API Version: v1.1user_idoptionalThe ID of the user for whom to return results for. Either an id orscreen_name is required for this method.screen_nameoptionalThe screen name of the user for whom to return results for. Either a idor screen_name is required for this method.include_entitiesoptionalThe entities node will be disincluded when set to false.8
    • Linked Data & Semantic Web TechnologyGetting Users1. public static void main(String args[]) throws TwitterException {2. TwitterUser tt = new TwitterUser ();3. String[] users = {"ACSpressroom", "AIP_Publishing", "PLoSNTDs"};4. List<User> userList = tt.twitter.lookupUsers(users);5. for(int i = 0; i < userList.size(); i++) {6. User user = userList.get(i);7. System.out.println(user.getId());8. }9. }9
    • Linked Data & Semantic Web TechnologyGET users/search• Resource URL– https://api.twitter.com/1.1/users/search.json• Parameters• Other Information– Requests per rate limit window: 180/user, 60/app– Authentication: Required– Response Object: Users– API Version: v1.1qrequiredThe search query to run against people search.pageoptionalSpecifies the page of results to retrieve.countoptionalThe number of potential user results to retrieve per page. This valuehas a maximum of 20.include_entitiesoptionalThe entities node will be disincluded when set to false.10
    • Linked Data & Semantic Web TechnologySearching Users1. public static void main(String args[]) throws TwitterException {2. TwitterUser tt = new TwitterUser ();3. List<User> userList = tt.twitter.searchUsers("journal", 1);4. for(int i = 0; i < userList.size(); i++) {5. User user = userList.get(i);6. System.out.println(user.getId() + ", " + user.getName());7. }8. }11
    • Linked Data & Semantic Web TechnologyREST API related to Friends & Followers12Resource DescriptionGET friends/idsReturns a cursored collection of user IDs for every user the specifieduser is following (otherwise known as their "friends"). At this time,results are ordered with the most recent following first — however,this ordering is subject to unannounced change and eventualconsistency issues....GET followers/idsReturns a cursored collection of user IDs for every user following thespecified user. At this time, results are ordered with the most recentfollowing first — however, this ordering is subject to unannouncedchange and eventual consistency issues. Results are given in groupsof 5,000 user...GET friendships/lookupReturns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided. Valuesfor connections can be: following, following_requested, followed_by,none.GET friendships/showReturns detailed information about the relationship between twoarbitrary users.
    • Linked Data & Semantic Web TechnologyTwitter4J Classes for Friends & Followers• FriendsFollowersResources Interface– Methods• IDs getFollowersIDs(long cursor)• IDs getFollowersIDs(long userId, long cursor)• IDs getFollowersIDs(String screenName, long cursor)• IDs getFriendsIDs(long cursor)• IDs getFriendsIDs(long userId, long cursor)• IDs getFriendsIDs(String screenName, long cursor)• IDs– A data interface representing array of numeric IDs.– Methods• long[] getIDs()13
    • Linked Data & Semantic Web TechnologyGET friends/ids & followers/ids• Resource URL– https://api.twitter.com/1.1/friends/ids.json– https://api.twitter.com/1.1/followers/ids.json• Parameters• Other Information– Requests per rate limit window: 180/user, 60/app– Authentication: Required– Response Object: Users– API Version: v1.1user_idoptionalThe ID of the user for whom to return results for.screen_nameoptionalThe screen name of the user for whom to return results for.cursorsemi-optionalCauses the list of connections to be broken into pages of no more than 5000IDs at a time. The number of IDs returned is not guaranteed to be 5000 assuspended users are filtered out after connections are queried. If no cursoris provided, a value of -1 will be assumed, which is the first "page."stringify_idsoptionalMany programming environments will not consume our Tweet ids due totheir size. Provide this option to have ids returned as strings instead.countoptionalSpecifies the number of IDs attempt retrieval of, up to a maximum of 5,000per distinct request. The value of count is best thought of as a limit to thenumber of results to return. When using the count parameter with thismethod, it is wise to use a consistent count value across all requests to thesame users collection. Usage of this parameter is encouraged inenvironments where all 5,000 IDs constitutes too large of a response.14
    • Linked Data & Semantic Web TechnologyGetting Friends and Followers1. public static void main(String args[]) throws TwitterException {2. TwitterUser tt = new TwitterUser ();3. IDs friends = tt.twitter.getFriendsIDs("ACSpressroom", -1);4. System.out.println("friends:");5. long[] ids = friends.getIDs();6. for(int i = 0; i < ids.length; i++) {7. System.out.println("t" + ids[i]);8. }9. IDs followers = tt.twitter.getFollowersIDs("ACSpressroom", -1);10. ids = followers.getIDs();11. System.out.println("followers:");12. for(int i = 0; i < ids.length; i++) {13. System.out.println("t" + ids[i]);14. }15. }15