Last active
December 9, 2015 03:27
-
-
Save clayadavis/398737bbc5028764d3ee to your computer and use it in GitHub Desktop.
BotOrNot REST Example
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 json | |
import requests | |
## `pip install tweepy` | |
import tweepy | |
auth = tweepy.OAuthHandler('consumer_key', 'consumer_secret') | |
auth.set_access_token('access_token_key', 'access_token_secret') | |
api = tweepy.API(auth, parser=tweepy.parsers.JSONParser()) | |
screen_name = '@clayadavis' | |
assert screen_name.startswith('@') | |
user_timeline = api.user_timeline(screen_name, count=200) | |
if user_timeline: | |
user = user_timeline[0]['user'] | |
else: | |
user = api.get_user(screen_name) | |
search = api.search(screen_name, count=100) | |
mentions = search['statuses'] | |
tweets = user_timeline + mentions | |
post_body = {'content': tweets} | |
## It is important to use str(user['id']) or user['id_str'] | |
## below because JSON doesn't do well with 64-bit int | |
post_body['meta'] = { | |
'user_id': user['id_str'], | |
'screen_name': screen_name, | |
} | |
url = 'http://truthy.indiana.edu/botornot/api/1/check_account/' | |
## The API accepts POST data in JSON format | |
resp = requests.post(url, data=json.dumps(post_body)) | |
resp_data = resp.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Recommended settings for number_of_tweets for timeline is 200 and 100 for search.