Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created June 17, 2019 23:58
Show Gist options
  • Save martin-martin/2f977381452a715dc9bae82a0ef3c34a to your computer and use it in GitHub Desktop.
Save martin-martin/2f977381452a715dc9bae82a0ef3c34a to your computer and use it in GitHub Desktop.
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
handle = 'twitter' # for example purposes; use any handle you want!
# fetch user object and friend count
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