Skip to Content
Learn
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:
  • Twitter handle of the celebrity
  • The number of desired Tweets (count)
  • 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)

Instructions

1.

Create a handle variable and set it equal to the Twitter username of a user you’d like to analyze, as in the example above.

2.

On the next line, call the GetUserTimeline() function on the twitter_api variable. Set it equal to a statuses variable.

Pass in the three necessary arguments, as in the example code above.

Folder Icon

Take this course for free

Already have an account?