Presentation is loading. Please wait.

Presentation is loading. Please wait.

Development of Twitter Applications Part 5. Users

Similar presentations


Presentation on theme: "Development of Twitter Applications Part 5. Users"— Presentation transcript:

1 Development of Twitter Applications Part 5. Users
Dr. Myungjin Lee

2 followers: another Twitter user who has followed you
Users Users in Twitter anyone or anything who tweets, follows, creates lists, has a home_timeline, can be mentioned, and can be looked up in bulk profile image name: a name that can be different from your username and is used to locate you on Twitter scree name (user name): unique and fewer than 15 characters to identify you on Twitter for replies and mentions location description url following (frineds): the quantity of other Twitter users you have chosen to follow followers: another Twitter user who has followed you

3 REST API related to Users
Resource Description GET users/lookup Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters. This method is especially useful when used in conjunction with collections of user IDs returned from GET friends/ids and GET followers/... users/show Returns a variety of information about the user specified by the required user_id or screen_name parameter. The author's most recent Tweet will be returned inline when possible. GET users/lookup is used to retrieve a bulk collection of user objects. users/search Provides a simple, relevance-based search interface to public user accounts on Twitter. Try querying by topical interest, full name, company name, location, or other criteria. Exact match searches are not supported. Only the first 1,000 matching results are available.

4 Users Primary Field Guide
Type Description created_at String The UTC datetime that the user account was created on Twitter description Nullable. The user-defined UTF-8 string describing their account. entities Entities Entities which have been parsed out of the url or description fields defined by the user. favourites_count Int The number of tweets this user has favorited in the account's lifetime. followers_count The number of followers this account currently has. friends_count The number of users this account is following (AKA their "followings"). id Int64 The integer representation of the unique identifier for this User. id_str The string representation of the unique identifier for this Tweet. lang The BCP 47 code for the user's self-declared user interface language. listed_count The number of public lists that this user is a member of. location Nullable. The user-defined location for this account's profile. name The name of the user, as they've defined it. protected Boolean When true, indicates that this user has chosen to protect their Tweets. screen_name The screen name, handle, or alias that this user identifies themselves with. status Tweets Nullable. If possible, the user's most recent tweet or retweet. statuses_count The number of tweets (including retweets) issued by the user. url Nullable. A URL provided by the user in association with their profile.

5 Twitter4J 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 information element 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()

6 GET users/show Resource URL Parameters Other Information
Parameters Other Information Requests per rate limit window: 180/user, 180/app Authentication: Required Response Object: Users API Version: v1.1 user_id required The ID of the user for whom to return results for. Either an id or screen_name is required for this method. screen_name The screen name of the user for whom to return results for. Either a id or screen_name is required for this method. include_entities optional The entities node will be disincluded when set to false.

7 Getting the User import java.util.List; import twitter4j.Twitter;
import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.User; public class TwitterUser { Twitter twitter = null; public TwitterUser() { this.twitter = TwitterFactory.getSingleton(); this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey, TwitterAccessToken.consumerSecret); this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken()); } public static void main(String args[]) throws TwitterException { TwitterUser tt = new TwitterUser (); User user = tt.twitter.showUser("ACSpressroom"); System.out.println(user.getId()); System.out.println(user.getName()); System.out.println(user.getScreenName()); System.out.println(user.getDescription()); System.out.println(user.getLocation()); System.out.println(user.getURL()); System.out.println(user.getProfileBackgroundImageURL());

8 GET users/lookup Resource URL Parameters Other Information
Parameters Other Information Requests per rate limit window: 180/user, 60/app Authentication: Required Response Object: Users API Version: v1.1 user_id optional The ID of the user for whom to return results for. Either an id or screen_name is required for this method. screen_name The screen name of the user for whom to return results for. Either a id or screen_name is required for this method. include_entities The entities node will be disincluded when set to false.

9 Getting Users public static void main(String args[]) throws TwitterException { TwitterUser tt = new TwitterUser (); String[] users = {"ACSpressroom", "AIP_Publishing", "PLoSNTDs"}; List<User> userList = tt.twitter.lookupUsers(users); for(int i = 0; i < userList.size(); i++) { User user = userList.get(i); System.out.println(user.getId()); }

10 GET users/search Resource URL Parameters Other Information
Parameters Other Information Requests per rate limit window: 180/user, 60/app Authentication: Required Response Object: Users API Version: v1.1 q required The search query to run against people search. page optional Specifies the page of results to retrieve. count The number of potential user results to retrieve per page. This value has a maximum of 20. include_entities The entities node will be disincluded when set to false.

11 Searching Users public static void main(String args[]) throws TwitterException { TwitterUser tt = new TwitterUser (); List<User> userList = tt.twitter.searchUsers("journal", 1); for(int i = 0; i < userList.size(); i++) { User user = userList.get(i); System.out.println(user.getId() + ", " + user.getName()); }

12 REST API related to Friends & Followers
Resource Description GET friends/ids Returns a cursored collection of user IDs for every user the specified user 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 eventual consistency issues.... GET followers/ids Returns a cursored collection of user IDs for every user following the specified user. At this time, results are ordered with the most recent following first — however, this ordering is subject to unannounced change and eventual consistency issues. Results are given in groups of 5,000 user... GET friendships/lookup Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none. GET friendships/show Returns detailed information about the relationship between two arbitrary users.

13 Twitter4J 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. long[] getIDs()

14 GET friends/ids & followers/ids
Resource URL Parameters Other Information Requests per rate limit window: 180/user, 60/app Authentication: Required Response Object: Users API Version: v1.1 user_id optional The ID of the user for whom to return results for. screen_name The screen name of the user for whom to return results for. cursor semi-optional Causes the list of connections to be broken into pages of no more than 5000 IDs at a time. The number of IDs returned is not guaranteed to be 5000 as suspended users are filtered out after connections are queried. If no cursor is provided, a value of -1 will be assumed, which is the first "page." stringify_ids Many programming environments will not consume our Tweet ids due to their size. Provide this option to have ids returned as strings instead. count Specifies the number of IDs attempt retrieval of, up to a maximum of 5,000 per distinct request. The value of count is best thought of as a limit to the number of results to return. When using the count parameter with this method, it is wise to use a consistent count value across all requests to the same user's collection. Usage of this parameter is encouraged in environments where all 5,000 IDs constitutes too large of a response.

15 Getting Friends and Followers
public static void main(String args[]) throws TwitterException { TwitterUser tt = new TwitterUser (); IDs friends = tt.twitter.getFriendsIDs("ACSpressroom", -1); System.out.println("friends:"); long[] ids = friends.getIDs(); for(int i = 0; i < ids.length; i++) { System.out.println("\t" + ids[i]); } IDs followers = tt.twitter.getFollowersIDs("ACSpressroom", -1); ids = followers.getIDs(); System.out.println("followers:");


Download ppt "Development of Twitter Applications Part 5. Users"

Similar presentations


Ads by Google