Database Reference
In-Depth Information
2.4
Collecting a User's Tweets
A Twitter user's Tweets are also known as status messages. A Tweet can be at most
140 characters in length. Tweets can be published using a wide range of mobile and
desktop clients and through the use of Twitter API. A special kind of Tweet is the
retweet, which is created when one user reposts the Tweet of another user. We will
discuss the utility of retweets in greater detail in Chaps. 4 and 5 .
A user's Tweets can be retrieved using both the REST and the Streaming API.
2.4.1
REST API
We can access a user's Tweets by using statuses/user_timeline 8 from the REST
APIs. Using this API, one can retrieve 3,200 of the most recent Tweets published
by a user including retweets. The API returns Twitter “Tweet” objects shown in
Listing 2.6 .
An example describing the process to access this API can be found in the
GetStatuses method summarized in Listing 2.7 .
Key Parameters : We can retrieve 200 Tweets on each page we collect. The
parameter max_id is used to paginate through the Tweets of a user. To retrieve the
next page we use the ID of the oldest Tweet in the list as the value of this parameter
in the subsequent request. Then, the API will retrieve only those Tweets whose IDs
are below the supplied value.
Rate Limit : An application is allowed 300 requests within a rate limit window
and up to 180 requests can be made using the credentials of a user.
Listing 2.6
An example of Twitter Tweet object
{
"text" : "This is the first tweet." ,
"lang" : "en" ,
"id" : 352914247774248960,
"source" : "web" ,
"retweet_count" :0,
"created_at" : "Thu Jul 04 22:18:08 +0000 2013" ,
//Other Tweet fields
...
"place" :{
"place_type" : "city" ,
"name" : "Tempe" ,
"country_code" : "US" ,
"url" : "https://api.twitter.com/1.1/geo/id/7
cb7440bcf83d464.json" ,
"country" : "United States" ,
8 https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
 
Search WWH ::




Custom Search