Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tweepy
- auth = tweepy.OAuthHandler('consumer key', 'consumer secret')
- auth.set_access_token('access key', 'access secret')
- api = tweepy.API(auth)
- user= "karpathy" #me :)
- #limit per hour is 350 calls
- limit= api.rate_limit_status()['remaining_hits']
- print 'you have', limit, 'API calls remaining until next hour'
- #retrieve only the latest 100 of people who I follow
- #COST: 1 API call = 100 users
- for friend in tweepy.Cursor(api.friends, id=user).items(100):
- #friend is an object with some fields
- print friend.screen_name
- #to retrieve all followers etc, just leave the argument to items() blank.
- #retrieve 100 of my latest followers
- #COST: 1 API call = 100 users
- for follower in tweepy.Cursor(api.followers).items(100):
- print follower.screen_name
- #all status updates from user.
- #COST: 1 API call= 20 users
- for status in tweepy.Cursor(api.user_timeline, id=user).items(20):
- #status is an object with many fields and info
- print status.text
- limit= api.rate_limit_status()['remaining_hits']
- print 'now you only have', limit, 'API calls.'
Advertisement
Add Comment
Please, Sign In to add comment