Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created June 22, 2018 12:24
Show Gist options
  • Save martin-martin/2c0a40b9295eb696b62f35f063fac110 to your computer and use it in GitHub Desktop.
Save martin-martin/2c0a40b9295eb696b62f35f063fac110 to your computer and use it in GitHub Desktop.
get user's friend count from twitter using tweepy
import os
import tweepy
# fetch the secrets from our virtual environment variables
CONSUMER_KEY = os.environ['TWITTER_CONSUMER_KEY']
CONSUMER_SECRET = os.environ['TWITTER_CONSUMER_SECRET']
ACCESS_TOKEN = os.environ['TWITTER_ACCESS_TOKEN']
ACCESS_SECRET = os.environ['TWITTER_ACCESS_SECRET']
# authenticate to the service we're accessing
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
# create the connection
api = tweepy.API(auth)
# define a handle to inspect for quicker reference
handle = 'twitter' # for example purposes; prop any handle you want!
user = api.get_user(handle)
num_friends = user.friends_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment