Database Reference
In-Depth Information
JSONObject jobj = new JSONObject(content.
toString());
// Step 5: Retrieve the token for the next
request
cursor = jobj.getLong( "next_cursor" );
JSONArray idlist = jobj.getJSONArray( "users" );
for(int i=0;i<idlist.length();i++) {
followers.put(idlist.getJSONObject(i));
}
...
return followers;
}
Source: Chapter2/restapi/RESTApiExample.java
2.3.1
Collecting the Followers of a User
The followers of a user can be crawled from Twitter using the endpoint follow-
ers/list , 6 by employing the method GetFollowers summarized in Listing 2.4 .The
response from Twitter consists of an array of user profile objects such as the one
described in Listing 2.3
Key Parameters : screen_name or user_id is mandatory to access the API.
Each request returns a maximum of 15 followers of the specified user in the form of
a Twitter User object. The parameter “cursor” can be used to paginate through the
results. Each request returns the cursor for use in the request for the next page.
Rate Limit : A maximum of 15 API calls from a user and 30 API calls from an
application are allowed within a rate limit window.
2.3.2
Collecting the Friends of a User
The friends of a user can be crawled using the Twitter API friends/list 7 by employing
the method GetFriends , which is summarized in Listing 2.5 . The method constructs
a call to the API and takes a valid Twitter username as the parameter. It uses the
cursor to retrieve all the friends of a user and if the API limit is reached, it will wait
until the quota has been renewed.
Key Parameters : As with the followers API, a valid screen_name or
user_id is mandatory. Each request returns a list of 20 friends of a user as Twitter
User objects. The parameter “cursor” can be used to paginate through the results.
Each request returns the cursor to be used in the request for the next page.
6 https://dev.twitter.com/docs/api/1.1/get/followers/list
7 https://dev.twitter.com/docs/api/1.1/get/friends/list
 
Search WWH ::




Custom Search