TwtitterAPI
Install
  • pip install TwitterAPI
  • Create API
    from TwitterAPI import TwitterAPI
    from t import ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET
    
    api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
    		
    request
  • param resource, valid data endpoint
  • param params, dictionary with endpoint parameters or None
  • param files, dictionary with multipart-encoded file or None
  • param method_override, request method to override or None
  • 		
    Tweet
    r = api.request('statuses/update', {'status':'This is a tweet!'})
    		
    Search
    r = api.request('search/tweets', {'q':'valdosta state'})
    for item in r:
            print(item['id'])
    		
    Search by Geocode
    r = api.request('statuses/filter', {'locations':'-74,40,-73,41', 'q': 'valdosta state'})
    r = api.request('search/tweets', {'geocode':'30.4433237,-84.2777568,1mi', 'q':'FSU'})
    		
    Premium Search
    r = api.request('tweets/search/%s/:%s' % ('30day', 'SearchThirtyDays'), {'query':'valdosta state'})
    r = api.request('tweets/search/%s/:%s' % ('30day', 'SearchThirtyDays'), {'query':'valdosta state', 'fromDate':'201910200000', 'toDate': '201910310000', 'maxResults':100})
    
    		
    Search more than 100 tweets
    curl -X POST "https://api.twitter.com/1.1/tweets/search/30day/SearchThirtyDays.json" -d '{"query":"Valdosta State","maxResults":"100","fromDate":"201910200000","toDate":"201910310000"}' -H "Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAIRWAwEAAAAALRrtvjL3wDGnv%2FuA0EO463TjzLc%3DzuLJ3ypKMwrp59WQ4fY6TuAKXN1jqq4VEj4TDx9AFAzWj9qeg4" > junk
    		
    import json
    
    with open('junk') as json_file:
        data = json.load(json_file)
        print(data['next']) # read the next token
    		
    curl -X POST "https://api.twitter.com/1.1/tweets/search/30day/SearchThirtyDays.json" -d '{"query":"Valdosta State","maxResults":"100","fromDate":"201910200000","toDate":"201910310000", "next":"eyJtYXhJZCI6MTE4OTU2OTIzNjAyNjQ3ODU5M30="}' -H "Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAIRWAwEAAAAALRrtvjL3wDGnv%2FuA0EO463TjzLc%3DzuLJ3ypKMwrp59WQ4fY6TuAKXN1jqq4VEj4TDx9AFAzWj9qeg4" > junk_2
    		
    Reference
  • Data Endpoint
  • Tutorial