TwitterAPI 2.2 documentation

TwitterAPI.TwitterAPI

«  Tiny Examples   ::   Contents   ::   TwitterAPI.TwitterRestPager  »

TwitterAPI.TwitterAPI

class TwitterAPI.TwitterAPI.TwitterAPI(consumer_key=None, consumer_secret=None, access_token_key=None, access_token_secret=None, auth_type='oAuth1', proxy_url=None)

Access REST API or Streaming API resources.

Parameters:
  • consumer_key – Twitter application consumer key
  • consumer_secret – Twitter application consumer secret
  • access_token_key – Twitter application access token key
  • access_token_secret – Twitter application access token secret
  • auth_type – “oAuth1” (default) or “oAuth2”
  • proxy_url – HTTPS proxy URL (ex. “https://USER:PASSWORD@SERVER:PORT”)
request(resource, params=None, files=None)

Request a Twitter REST API or Streaming API resource.

Parameters:
  • resource – A valid Twitter endpoint (ex. “search/tweets”)
  • params – Dictionary with endpoint parameters or None (default)
  • files – Dictionary with multipart-encoded file or None (default)
Returns:

TwitterAPI.TwitterResponse object

class TwitterAPI.TwitterAPI.TwitterResponse(response, stream)

Response from either a REST API or Streaming API resource call.

Parameters:
  • response – The requests.Response object returned by the API call
  • stream – Boolean connection type (True if a streaming connection)
get_iterator()
Returns:Iterator for tweets or other message objects in response.
get_rest_quota()
Returns:Quota information in the REST-only response header.
headers None
Returns:Dictionary of API response header contents.
json()
Returns:response as JSON object.
status_code None
Returns:HTTP response status code.
text None
Returns:Raw API response text.

«  Tiny Examples   ::   Contents   ::   TwitterAPI.TwitterRestPager  »