Using the Twitter API

Querying Twitter II

Great! But to retrieve data from Twitter, we need to make an actual call to the API. So far, we've only created the object (twitter_api)that represents the Twitter API we'll interact with.

To make the call, we'll do the following:

  1. Create a handle variable (will be set to a Twitter username)
  2. Call the GetUserTimeline() method on the twitter_api object we created in the last exercise and pass in the following three arguments to the method:

  3. Twitter handle of the celebrity

  4. The number of desired Tweets (count)
  5. A retweet flag (include_rts is set to false in order to avoid retrieving retweets)

3. Create a statuses variable set to the code from Step 2 above

Here's an example:

# This example uses Codecademy's twitter handle
handle = "@Codecademy"

statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False)
Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.