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:
- Create a
handlevariable (will be set to a Twitter username)
- Call the
GetUserTimeline()method on the
twitter_apiobject 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 (
- A retweet flag (
include_rtsis set to
falsein 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)
handle variable and set it equal to the Twitter username of a user you’d like to analyze, as in the example above.
On the next line, call the
GetUserTimeline() function on the
twitter_api variable. Set it equal to a
Pass in the three necessary arguments, as in the example code above.