Created
June 22, 2018 12:24
-
-
Save martin-martin/2c0a40b9295eb696b62f35f063fac110 to your computer and use it in GitHub Desktop.
get user's friend count from twitter using tweepy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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