Code Snippets

Introduction

Here are some code snippets to help you out with using Tweepy. Feel free to contribute your own snippets or improve the ones here!

OAuth

auth = tweepy.OAuthHandler("consumer_key", "consumer_secret")

# Redirect user to Twitter to authorize
redirect_user(auth.get_authorization_url())

# Get access token
auth.get_access_token("verifier_value")

# Construct the API instance
api = tweepy.API(auth)

FollowAll

This snippet will follow every follower of the authenticated user.

for follower in tweepy.Cursor(api.followers).items():
    follower.follow()

Table Of Contents

Previous topic

Authentication Tutorial

Next topic

Cursor Tutorial

This Page