Learn
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
handle
variable (will be set to a Twitter username) - Call the
GetUserTimeline()
method on thetwitter_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 tofalse
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.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.