Updated to Twython 3.7.0

This commit is contained in:
Manuel Cortez 2018-09-22 12:03:59 -05:00
parent 211d43aa30
commit 01a6c65c82
6 changed files with 292 additions and 184 deletions

View File

@ -19,7 +19,7 @@ Questions, comments? ryan@venodesigns.net
""" """
__author__ = 'Ryan McGrath <ryan@venodesigns.net>' __author__ = 'Ryan McGrath <ryan@venodesigns.net>'
__version__ = '3.6.0' __version__ = '3.7.0'
from .api import Twython from .api import Twython
from .streaming import TwythonStreamer from .streaming import TwythonStreamer

View File

@ -19,6 +19,7 @@ from requests_oauthlib import OAuth1, OAuth2
from . import __version__ from . import __version__
from .advisory import TwythonDeprecationWarning from .advisory import TwythonDeprecationWarning
from .compat import json, urlencode, parse_qsl, quote_plus, str, is_py2 from .compat import json, urlencode, parse_qsl, quote_plus, str, is_py2
from .compat import urlsplit
from .endpoints import EndpointsMixin from .endpoints import EndpointsMixin
from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError
from .helpers import _transparent_params from .helpers import _transparent_params
@ -134,13 +135,13 @@ class Twython(EndpointsMixin, object):
def __repr__(self): def __repr__(self):
return '<Twython: %s>' % (self.app_key) return '<Twython: %s>' % (self.app_key)
def _request(self, url, method='GET', params=None, api_call=None, encode_json=False): def _request(self, url, method='GET', params=None, api_call=None, json_encoded=False):
"""Internal request method""" """Internal request method"""
method = method.lower() method = method.lower()
params = params or {} params = params or {}
func = getattr(self.client, method) func = getattr(self.client, method)
if type(params) is dict and encode_json == False: if isinstance(params, dict) and json_encoded == False:
params, files = _transparent_params(params) params, files = _transparent_params(params)
else: else:
params = params params = params
@ -155,15 +156,14 @@ class Twython(EndpointsMixin, object):
if method == 'get': if method == 'get':
requests_args['params'] = params requests_args['params'] = params
else: else:
# Check for json_encoded so we will sent params as "data" or "json"
if encode_json == False: if json_encoded:
requests_args.update({ data_key = "json"
'files': files,
'data': params,
})
else: else:
requests_args.update({ data_key = "data"
'json': params, requests_args.update({
data_key: params,
'files': files,
}) })
try: try:
response = func(url, **requests_args) response = func(url, **requests_args)
@ -202,14 +202,14 @@ class Twython(EndpointsMixin, object):
error_message, error_message,
error_code=response.status_code, error_code=response.status_code,
retry_after=response.headers.get('X-Rate-Limit-Reset')) retry_after=response.headers.get('X-Rate-Limit-Reset'))
content="" content = ''
try: try:
if response.status_code == 204: if response.status_code == 204:
content = response.content content = response.content
else: else:
content = response.json() content = response.json()
except ValueError: except ValueError:
if response.content!="": if response.content != '':
raise TwythonError('Response was not valid JSON. \ raise TwythonError('Response was not valid JSON. \
Unable to decode.') Unable to decode.')
@ -235,7 +235,7 @@ class Twython(EndpointsMixin, object):
return error_message return error_message
def request(self, endpoint, method='GET', params=None, version='1.1', encode_json=False): def request(self, endpoint, method='GET', params=None, version='1.1', json_encoded=False):
"""Return dict of response received from Twitter's API """Return dict of response received from Twitter's API
:param endpoint: (required) Full url or Twitter API endpoint :param endpoint: (required) Full url or Twitter API endpoint
@ -251,6 +251,9 @@ class Twython(EndpointsMixin, object):
:param version: (optional) Twitter API version to access :param version: (optional) Twitter API version to access
(default 1.1) (default 1.1)
:type version: string :type version: string
:param json_encoded: (optional) Flag to indicate if this method should send data encoded as json
(default False)
:type json_encoded: bool
:rtype: dict :rtype: dict
""" """
@ -266,7 +269,7 @@ class Twython(EndpointsMixin, object):
url = '%s/%s.json' % (self.api_url % version, endpoint) url = '%s/%s.json' % (self.api_url % version, endpoint)
content = self._request(url, method=method, params=params, content = self._request(url, method=method, params=params,
api_call=url, encode_json=encode_json) api_call=url, json_encoded=json_encoded)
return content return content
@ -274,9 +277,9 @@ class Twython(EndpointsMixin, object):
"""Shortcut for GET requests via :class:`request`""" """Shortcut for GET requests via :class:`request`"""
return self.request(endpoint, params=params, version=version) return self.request(endpoint, params=params, version=version)
def post(self, endpoint, params=None, version='1.1', encode_json=False): def post(self, endpoint, params=None, version='1.1', json_encoded=False):
"""Shortcut for POST requests via :class:`request`""" """Shortcut for POST requests via :class:`request`"""
return self.request(endpoint, 'POST', params=params, version=version, encode_json=encode_json) return self.request(endpoint, 'POST', params=params, version=version, json_encoded=json_encoded)
def get_lastfunction_header(self, header, default_return_value=None): def get_lastfunction_header(self, header, default_return_value=None):
"""Returns a specific header from the last API call """Returns a specific header from the last API call
@ -513,19 +516,27 @@ class Twython(EndpointsMixin, object):
try: try:
if function.iter_mode == 'id': if function.iter_mode == 'id':
if 'max_id' not in params: # Set max_id in params to one less than lowest tweet id
# Add 1 to the id because since_id and if hasattr(function, 'iter_metadata'):
# max_id are inclusive # Get supplied next max_id
if hasattr(function, 'iter_metadata'): metadata = content.get(function.iter_metadata)
since_id = content[function.iter_metadata].get('since_id_str') if 'next_results' in metadata:
next_results = urlsplit(metadata['next_results'])
params = dict(parse_qsl(next_results.query))
else: else:
since_id = content[0]['id_str'] # No more results
params['since_id'] = (int(since_id) - 1) raise StopIteration
else:
# Twitter gives tweets in reverse chronological order:
params['max_id'] = str(int(content[-1]['id_str']) - 1)
elif function.iter_mode == 'cursor': elif function.iter_mode == 'cursor':
params['cursor'] = content['next_cursor_str'] params['cursor'] = content['next_cursor_str']
except (TypeError, ValueError): # pragma: no cover except (TypeError, ValueError): # pragma: no cover
raise TwythonError('Unable to generate next page of search \ raise TwythonError('Unable to generate next page of search \
results, `page` is not a number.') results, `page` is not a number.')
except (KeyError, AttributeError): #pragma no cover
raise TwythonError('Unable to generate next page of search \
results, content has unexpected structure.')
@staticmethod @staticmethod
def unicode2utf8(text): def unicode2utf8(text):
@ -587,6 +598,8 @@ class Twython(EndpointsMixin, object):
if display_text_start <= temp['start'] <= display_text_end: if display_text_start <= temp['start'] <= display_text_end:
temp['replacement'] = mention_html temp['replacement'] = mention_html
temp['start'] -= display_text_start
temp['end'] -= display_text_start
entities.append(temp) entities.append(temp)
else: else:
# Make the '@username' at the start, before # Make the '@username' at the start, before
@ -598,8 +611,8 @@ class Twython(EndpointsMixin, object):
if 'hashtags' in tweet['entities']: if 'hashtags' in tweet['entities']:
for entity in tweet['entities']['hashtags']: for entity in tweet['entities']['hashtags']:
temp = {} temp = {}
temp['start'] = entity['indices'][0] temp['start'] = entity['indices'][0] - display_text_start
temp['end'] = entity['indices'][1] temp['end'] = entity['indices'][1] - display_text_start
url_html = '<a href="https://twitter.com/search?q=%%23%(hashtag)s" class="twython-hashtag">#%(hashtag)s</a>' % {'hashtag': entity['text']} url_html = '<a href="https://twitter.com/search?q=%%23%(hashtag)s" class="twython-hashtag">#%(hashtag)s</a>' % {'hashtag': entity['text']}
@ -610,8 +623,8 @@ class Twython(EndpointsMixin, object):
if 'symbols' in tweet['entities']: if 'symbols' in tweet['entities']:
for entity in tweet['entities']['symbols']: for entity in tweet['entities']['symbols']:
temp = {} temp = {}
temp['start'] = entity['indices'][0] temp['start'] = entity['indices'][0] - display_text_start
temp['end'] = entity['indices'][1] temp['end'] = entity['indices'][1] - display_text_start
url_html = '<a href="https://twitter.com/search?q=%%24%(symbol)s" class="twython-symbol">$%(symbol)s</a>' % {'symbol': entity['text']} url_html = '<a href="https://twitter.com/search?q=%%24%(symbol)s" class="twython-symbol">$%(symbol)s</a>' % {'symbol': entity['text']}
@ -622,8 +635,8 @@ class Twython(EndpointsMixin, object):
if 'urls' in tweet['entities']: if 'urls' in tweet['entities']:
for entity in tweet['entities']['urls']: for entity in tweet['entities']['urls']:
temp = {} temp = {}
temp['start'] = entity['indices'][0] temp['start'] = entity['indices'][0] - display_text_start
temp['end'] = entity['indices'][1] temp['end'] = entity['indices'][1] - display_text_start
if use_display_url and entity.get('display_url') and not use_expanded_url: if use_display_url and entity.get('display_url') and not use_expanded_url:
shown_url = entity['display_url'] shown_url = entity['display_url']
@ -640,26 +653,30 @@ class Twython(EndpointsMixin, object):
else: else:
suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html) suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html)
if 'media' in tweet['entities']: if 'media' in tweet['entities'] and len(tweet['entities']['media']) > 0:
for entity in tweet['entities']['media']: # We just link to the overall URL for the tweet's media,
temp = {} # rather than to each individual item.
temp['start'] = entity['indices'][0] # So, we get the URL from the first media item:
temp['end'] = entity['indices'][1] entity = tweet['entities']['media'][0]
if use_display_url and entity.get('display_url') and not use_expanded_url: temp = {}
shown_url = entity['display_url'] temp['start'] = entity['indices'][0]
elif use_expanded_url and entity.get('expanded_url'): temp['end'] = entity['indices'][1]
shown_url = entity['expanded_url']
else:
shown_url = entity['url']
url_html = '<a href="%s" class="twython-media">%s</a>' % (entity['url'], shown_url) if use_display_url and entity.get('display_url') and not use_expanded_url:
shown_url = entity['display_url']
elif use_expanded_url and entity.get('expanded_url'):
shown_url = entity['expanded_url']
else:
shown_url = entity['url']
if display_text_start <= temp['start'] <= display_text_end: url_html = '<a href="%s" class="twython-media">%s</a>' % (entity['url'], shown_url)
temp['replacement'] = url_html
entities.append(temp) if display_text_start <= temp['start'] <= display_text_end:
else: temp['replacement'] = url_html
suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html) entities.append(temp)
else:
suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html)
# Now do all the replacements, starting from the end, so that the # Now do all the replacements, starting from the end, so that the
# start/end indices still work: # start/end indices still work:

View File

@ -25,7 +25,7 @@ except ImportError:
if is_py2: if is_py2:
from urllib import urlencode, quote_plus from urllib import urlencode, quote_plus
from urlparse import parse_qsl from urlparse import parse_qsl, urlsplit
str = unicode str = unicode
basestring = basestring basestring = basestring
@ -33,7 +33,7 @@ if is_py2:
elif is_py3: elif is_py3:
from urllib.parse import urlencode, quote_plus, parse_qsl from urllib.parse import urlencode, quote_plus, parse_qsl, urlsplit
str = str str = str
basestring = (str, bytes) basestring = (str, bytes)

View File

@ -10,8 +10,8 @@ as a keyword argument.
e.g. Twython.retweet(id=12345) e.g. Twython.retweet(id=12345)
This map is organized the order functions are documented at: Official documentation for Twitter API endpoints can be found at:
https://dev.twitter.com/docs/api/1.1 https://developer.twitter.com/en/docs/api-reference-index
""" """
import json import json
@ -34,7 +34,7 @@ class EndpointsMixin(object):
@screen_name) for the authenticating user. @screen_name) for the authenticating user.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-mentions_timeline
""" """
return self.get('statuses/mentions_timeline', params=params) return self.get('statuses/mentions_timeline', params=params)
@ -42,9 +42,10 @@ class EndpointsMixin(object):
def get_user_timeline(self, **params): def get_user_timeline(self, **params):
"""Returns a collection of the most recent Tweets posted by the user """Returns a collection of the most recent Tweets posted by the user
indicated by the screen_name or user_id parameters. indicated by the ``screen_name`` or ``user_id`` parameters.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline Docs:
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline
""" """
return self.get('statuses/user_timeline', params=params) return self.get('statuses/user_timeline', params=params)
@ -54,7 +55,8 @@ class EndpointsMixin(object):
"""Returns a collection of the most recent Tweets and retweets """Returns a collection of the most recent Tweets and retweets
posted by the authenticating user and the users they follow. posted by the authenticating user and the users they follow.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline Docs:
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline
""" """
return self.get('statuses/home_timeline', params=params) return self.get('statuses/home_timeline', params=params)
@ -64,7 +66,8 @@ class EndpointsMixin(object):
"""Returns the most recent tweets authored by the authenticating user """Returns the most recent tweets authored by the authenticating user
that have been retweeted by others. that have been retweeted by others.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets_of_me
""" """
return self.get('statuses/retweets_of_me', params=params) return self.get('statuses/retweets_of_me', params=params)
@ -74,34 +77,38 @@ class EndpointsMixin(object):
def get_retweets(self, **params): def get_retweets(self, **params):
"""Returns up to 100 of the first retweets of a given tweet. """Returns up to 100 of the first retweets of a given tweet.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-retweet-id
""" """
return self.get('statuses/retweets/%s' % params.get('id'), return self.get('statuses/retweets/%s' % params.get('id'),
params=params) params=params)
def show_status(self, **params): def show_status(self, **params):
"""Returns a single Tweet, specified by the id parameter """Returns a single Tweet, specified by the ``id`` parameter
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/show/%3Aid Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id
""" """
return self.get('statuses/show/%s' % params.get('id'), params=params) return self.get('statuses/show/%s' % params.get('id'), params=params)
def lookup_status(self, **params): def lookup_status(self, **params):
"""Returns fully-hydrated tweet objects for up to 100 tweets per """Returns fully-hydrated tweet objects for up to 100 tweets per
request, as specified by comma-separated values passed to the id request, as specified by comma-separated values passed to the ``id``
parameter. parameter.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/lookup Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-lookup
""" """
return self.post('statuses/lookup', params=params) return self.post('statuses/lookup', params=params)
def destroy_status(self, **params): def destroy_status(self, **params):
"""Destroys the status specified by the required ID parameter """Destroys the status specified by the required ``id`` parameter
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-destroy-id
""" """
return self.post('statuses/destroy/%s' % params.get('id')) return self.post('statuses/destroy/%s' % params.get('id'))
@ -109,15 +116,17 @@ class EndpointsMixin(object):
def update_status(self, **params): def update_status(self, **params):
"""Updates the authenticating user's current status, also known as tweeting """Updates the authenticating user's current status, also known as tweeting
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/update Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
""" """
return self.post('statuses/update', params=params) return self.post('statuses/update', params=params)
def retweet(self, **params): def retweet(self, **params):
"""Retweets a tweet specified by the id parameter """Retweets a tweet specified by the ``id`` parameter
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-retweet-id
""" """
return self.post('statuses/retweet/%s' % params.get('id')) return self.post('statuses/retweet/%s' % params.get('id'))
@ -127,7 +136,7 @@ class EndpointsMixin(object):
for upload. In other words, it creates a Tweet with a picture attached. for upload. In other words, it creates a Tweet with a picture attached.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update_with_media
""" """
warnings.warn( warnings.warn(
@ -140,12 +149,13 @@ class EndpointsMixin(object):
def upload_media(self, **params): def upload_media(self, **params):
"""Uploads media file to Twitter servers. The file will be available to be attached """Uploads media file to Twitter servers. The file will be available to be attached
to a status for 60 minutes. To attach to a update, pass a list of returned media ids to a status for 60 minutes. To attach to a update, pass a list of returned media ids
to the 'update_status' method using the 'media_ids' param. to the :meth:`update_status` method using the ``media_ids`` param.
Docs: Docs:
https://dev.twitter.com/rest/reference/post/media/upload https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
""" """
# https://dev.twitter.com/rest/reference/get/media/upload-status # https://developer.twitter.com/en/docs/media/upload-media/api-reference/get-media-upload-status
if params and params.get('command', '') == 'STATUS': if params and params.get('command', '') == 'STATUS':
return self.get('https://upload.twitter.com/1.1/media/upload.json', params=params) return self.get('https://upload.twitter.com/1.1/media/upload.json', params=params)
@ -153,7 +163,10 @@ class EndpointsMixin(object):
def create_metadata(self, **params): def create_metadata(self, **params):
""" Adds metadata to a media element, such as image descriptions for visually impaired. """ Adds metadata to a media element, such as image descriptions for visually impaired.
Docs: https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create
Docs:
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create
""" """
params = json.dumps(params) params = json.dumps(params)
return self.post("https://upload.twitter.com/1.1/media/metadata/create.json", params=params) return self.post("https://upload.twitter.com/1.1/media/metadata/create.json", params=params)
@ -161,7 +174,7 @@ class EndpointsMixin(object):
def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False): def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False):
"""Uploads video file to Twitter servers in chunks. The file will be available to be attached """Uploads video file to Twitter servers in chunks. The file will be available to be attached
to a status for 60 minutes. To attach to a update, pass a list of returned media ids to a status for 60 minutes. To attach to a update, pass a list of returned media ids
to the 'update_status' method using the 'media_ids' param. to the :meth:`update_status` method using the ``media_ids`` param.
Upload happens in 3 stages: Upload happens in 3 stages:
- INIT call with size of media to be uploaded(in bytes). If this is more than 15mb, twitter will return error. - INIT call with size of media to be uploaded(in bytes). If this is more than 15mb, twitter will return error.
@ -171,7 +184,8 @@ class EndpointsMixin(object):
Twitter media upload api expects each chunk to be not more than 5mb. We are sending chunk of 1mb each. Twitter media upload api expects each chunk to be not more than 5mb. We are sending chunk of 1mb each.
Docs: Docs:
https://dev.twitter.com/rest/public/uploading-media#chunkedupload https://developer.twitter.com/en/docs/media/upload-media/uploading-media/chunked-media-upload
""" """
upload_url = 'https://upload.twitter.com/1.1/media/upload.json' upload_url = 'https://upload.twitter.com/1.1/media/upload.json'
if not size: if not size:
@ -216,7 +230,7 @@ class EndpointsMixin(object):
response = self.post(upload_url, params=params) response = self.post(upload_url, params=params)
# Only get the status if explicity asked to # Only get the status if explicity asked to
# Default to False # Default to False
if check_progress: if check_progress:
@ -250,16 +264,18 @@ class EndpointsMixin(object):
"""Returns information allowing the creation of an embedded """Returns information allowing the creation of an embedded
representation of a Tweet on third party sites. representation of a Tweet on third party sites.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/oembed Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed
""" """
return self.get('statuses/oembed', params=params) return self.get('statuses/oembed', params=params)
def get_retweeters_ids(self, **params): def get_retweeters_ids(self, **params):
"""Returns a collection of up to 100 user IDs belonging to users who """Returns a collection of up to 100 user IDs belonging to users who
have retweeted the tweet specified by the id parameter. have retweeted the tweet specified by the ``id`` parameter.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweeters-ids
""" """
return self.get('statuses/retweeters/ids', params=params) return self.get('statuses/retweeters/ids', params=params)
@ -270,7 +286,8 @@ class EndpointsMixin(object):
def search(self, **params): def search(self, **params):
"""Returns a collection of relevant Tweets matching a specified query. """Returns a collection of relevant Tweets matching a specified query.
Docs: https://dev.twitter.com/docs/api/1.1/get/search/tweets Docs:
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
""" """
return self.get('search/tweets', params=params) return self.get('search/tweets', params=params)
@ -282,7 +299,8 @@ class EndpointsMixin(object):
def get_direct_messages(self, **params): def get_direct_messages(self, **params):
"""Returns the 20 most recent direct messages sent to the authenticating user. """Returns the 20 most recent direct messages sent to the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/direct_messages Docs:
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events
""" """
return self.get('direct_messages/events/list', params=params) return self.get('direct_messages/events/list', params=params)
@ -291,24 +309,27 @@ class EndpointsMixin(object):
def get_sent_messages(self, **params): def get_sent_messages(self, **params):
"""Returns the 20 most recent direct messages sent by the authenticating user. """Returns the 20 most recent direct messages sent by the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent Docs:
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-sent-message
""" """
return self.get('direct_messages/sent', params=params) return self.get('direct_messages/sent', params=params)
get_sent_messages.iter_mode = 'id' get_sent_messages.iter_mode = 'id'
def get_direct_message(self, **params): def get_direct_message(self, **params):
"""Returns a single direct message, specified by an id parameter. """Returns a single direct message, specified by an ``id`` parameter.
Docs: https://dev.twitter.com/docs/api/1.1/get/direct_messages/show Docs:
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-event
""" """
return self.get('direct_messages/events/show', params=params) return self.get('direct_messages/events/show', params=params)
def destroy_direct_message(self, **params): def destroy_direct_message(self, **params):
"""Destroys the direct message specified in the required id parameter """Destroys the direct message specified in the required ``id`` parameter
Docs: https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy Docs:
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message
""" """
return self.post('direct_messages/destroy', params=params) return self.post('direct_messages/destroy', params=params)
@ -317,10 +338,11 @@ class EndpointsMixin(object):
"""Sends a new direct message to the specified user from the """Sends a new direct message to the specified user from the
authenticating user. authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/direct_messages/new Docs:
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event
""" """
return self.post('direct_messages/events/new', params=params, encode_json=True) return self.post('direct_messages/events/new', params=params, json_encoded=True)
# Friends & Followers # Friends & Followers
def get_user_ids_of_blocked_retweets(self, **params): def get_user_ids_of_blocked_retweets(self, **params):
@ -328,7 +350,7 @@ class EndpointsMixin(object):
user does not want to receive retweets from. user does not want to receive retweets from.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/friendships/no_retweets/ids https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-no_retweets-ids
""" """
return self.get('friendships/no_retweets/ids', params=params) return self.get('friendships/no_retweets/ids', params=params)
@ -337,7 +359,8 @@ class EndpointsMixin(object):
"""Returns a cursored collection of user IDs for every user the """Returns a cursored collection of user IDs for every user the
specified user is following (otherwise known as their "friends"). specified user is following (otherwise known as their "friends").
Docs: https://dev.twitter.com/docs/api/1.1/get/friends/ids Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids
""" """
return self.get('friends/ids', params=params) return self.get('friends/ids', params=params)
@ -348,7 +371,8 @@ class EndpointsMixin(object):
"""Returns a cursored collection of user IDs for every user """Returns a cursored collection of user IDs for every user
following the specified user. following the specified user.
Docs: https://dev.twitter.com/docs/api/1.1/get/followers/ids Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids
""" """
return self.get('followers/ids', params=params) return self.get('followers/ids', params=params)
@ -357,9 +381,10 @@ class EndpointsMixin(object):
def lookup_friendships(self, **params): def lookup_friendships(self, **params):
"""Returns the relationships of the authenticating user to the """Returns the relationships of the authenticating user to the
comma-separated list of up to 100 screen_names or user_ids provided. comma-separated list of up to 100 ``screen_names`` or ``user_ids`` provided.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/lookup Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-lookup
""" """
return self.get('friendships/lookup', params=params) return self.get('friendships/lookup', params=params)
@ -368,7 +393,8 @@ class EndpointsMixin(object):
"""Returns a collection of numeric IDs for every user who has a """Returns a collection of numeric IDs for every user who has a
pending request to follow the authenticating user. pending request to follow the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/incoming Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming
""" """
return self.get('friendships/incoming', params=params) return self.get('friendships/incoming', params=params)
@ -379,7 +405,8 @@ class EndpointsMixin(object):
"""Returns a collection of numeric IDs for every protected user for """Returns a collection of numeric IDs for every protected user for
whom the authenticating user has a pending follow request. whom the authenticating user has a pending follow request.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-outgoing
""" """
return self.get('friendships/outgoing', params=params) return self.get('friendships/outgoing', params=params)
@ -388,18 +415,20 @@ class EndpointsMixin(object):
def create_friendship(self, **params): def create_friendship(self, **params):
"""Allows the authenticating users to follow the user specified """Allows the authenticating users to follow the user specified
in the ID parameter. in the ``id`` parameter.
Docs: https://dev.twitter.com/docs/api/1.1/post/friendships/create Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create
""" """
return self.post('friendships/create', params=params) return self.post('friendships/create', params=params)
def destroy_friendship(self, **params): def destroy_friendship(self, **params):
"""Allows the authenticating user to unfollow the user specified """Allows the authenticating user to unfollow the user specified
in the ID parameter. in the ``id`` parameter.
Docs: https://dev.twitter.com/docs/api/1.1/post/friendships/destroy Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy
""" """
return self.post('friendships/destroy', params=params) return self.post('friendships/destroy', params=params)
@ -408,7 +437,8 @@ class EndpointsMixin(object):
"""Allows one to enable or disable retweets and device notifications """Allows one to enable or disable retweets and device notifications
from the specified user. from the specified user.
Docs: https://dev.twitter.com/docs/api/1.1/post/friendships/update Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-update
""" """
return self.post('friendships/update', params=params) return self.post('friendships/update', params=params)
@ -417,7 +447,8 @@ class EndpointsMixin(object):
"""Returns detailed information about the relationship between two """Returns detailed information about the relationship between two
arbitrary users. arbitrary users.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/show Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show
""" """
return self.get('friendships/show', params=params) return self.get('friendships/show', params=params)
@ -426,7 +457,8 @@ class EndpointsMixin(object):
"""Returns a cursored collection of user objects for every user the """Returns a cursored collection of user objects for every user the
specified user is following (otherwise known as their "friends"). specified user is following (otherwise known as their "friends").
Docs: https://dev.twitter.com/docs/api/1.1/get/friends/list Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-list
""" """
return self.get('friends/list', params=params) return self.get('friends/list', params=params)
@ -437,7 +469,8 @@ class EndpointsMixin(object):
"""Returns a cursored collection of user objects for users """Returns a cursored collection of user objects for users
following the specified user. following the specified user.
Docs: https://dev.twitter.com/docs/api/1.1/get/followers/list Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-list
""" """
return self.get('followers/list', params=params) return self.get('followers/list', params=params)
@ -449,7 +482,8 @@ class EndpointsMixin(object):
"""Returns settings (including current trend, geo and sleep time """Returns settings (including current trend, geo and sleep time
information) for the authenticating user. information) for the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/account/settings Docs:
https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-settings
""" """
return self.get('account/settings', params=params) return self.get('account/settings', params=params)
@ -460,7 +494,7 @@ class EndpointsMixin(object):
code and an error message if not. code and an error message if not.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials
""" """
return self.get('account/verify_credentials', params=params) return self.get('account/verify_credentials', params=params)
@ -468,7 +502,8 @@ class EndpointsMixin(object):
def update_account_settings(self, **params): def update_account_settings(self, **params):
"""Updates the authenticating user's settings. """Updates the authenticating user's settings.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/settings Docs:
https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-settings
""" """
return self.post('account/settings', params=params) return self.post('account/settings', params=params)
@ -486,7 +521,8 @@ class EndpointsMixin(object):
"""Sets values that users are able to set under the "Account" tab of their """Sets values that users are able to set under the "Account" tab of their
settings page. settings page.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_profile Docs:
https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile
""" """
return self.post('account/update_profile', params=params) return self.post('account/update_profile', params=params)
@ -495,26 +531,35 @@ class EndpointsMixin(object):
"""Updates the authenticating user's profile background image. """Updates the authenticating user's profile background image.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_background_image
""" """
return self.post('account/update_profile_banner', params=params) return self.post('account/update_profile_banner', params=params)
def update_profile_colors(self, **params): def update_profile_colors(self, **params): # pragma: no cover
"""Sets one or more hex values that control the color scheme of the """Sets one or more hex values that control the color scheme of the
authenticating user's profile page on twitter.com. authenticating user's profile page on twitter.com.
This method is deprecated, replaced by the ``profile_link_color``
parameter to :meth:`update_profile`.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile
""" """
warnings.warn(
'This method is deprecated. You should use the'
' profile_link_color parameter in Twython.update_profile instead.',
TwythonDeprecationWarning,
stacklevel=2
)
return self.post('account/update_profile_colors', params=params) return self.post('account/update_profile_colors', params=params)
def update_profile_image(self, **params): # pragma: no cover def update_profile_image(self, **params): # pragma: no cover
"""Updates the authenticating user's profile image. """Updates the authenticating user's profile image.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image
""" """
return self.post('account/update_profile_image', params=params) return self.post('account/update_profile_image', params=params)
@ -523,7 +568,8 @@ class EndpointsMixin(object):
"""Returns a collection of user objects that the authenticating user """Returns a collection of user objects that the authenticating user
is blocking. is blocking.
Docs: https://dev.twitter.com/docs/api/1.1/get/blocks/list Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-blocks-list
""" """
return self.get('blocks/list', params=params) return self.get('blocks/list', params=params)
@ -533,7 +579,8 @@ class EndpointsMixin(object):
def list_block_ids(self, **params): def list_block_ids(self, **params):
"""Returns an array of numeric user ids the authenticating user is blocking. """Returns an array of numeric user ids the authenticating user is blocking.
Docs: https://dev.twitter.com/docs/api/1.1/get/blocks/ids Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-blocks-ids
""" """
return self.get('blocks/ids', params=params) return self.get('blocks/ids', params=params)
@ -543,35 +590,39 @@ class EndpointsMixin(object):
def create_block(self, **params): def create_block(self, **params):
"""Blocks the specified user from following the authenticating user. """Blocks the specified user from following the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/blocks/create Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-blocks-create
""" """
return self.post('blocks/create', params=params) return self.post('blocks/create', params=params)
def destroy_block(self, **params): def destroy_block(self, **params):
"""Un-blocks the user specified in the ID parameter for the """Un-blocks the user specified in the ``id`` parameter for the
authenticating user. authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/blocks/destroy Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-blocks-destroy
""" """
return self.post('blocks/destroy', params=params) return self.post('blocks/destroy', params=params)
def lookup_user(self, **params): def lookup_user(self, **params):
"""Returns fully-hydrated user objects for up to 100 users per request, """Returns fully-hydrated user objects for up to 100 users per request,
as specified by comma-separated values passed to the user_id and/or as specified by comma-separated values passed to the ``user_id`` and/or
screen_name parameters. ``screen_name`` parameters.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/lookup Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup
""" """
return self.get('users/lookup', params=params) return self.get('users/lookup', params=params)
def show_user(self, **params): def show_user(self, **params):
"""Returns a variety of information about the user specified by the """Returns a variety of information about the user specified by the
required user_id or screen_name parameter. required ``user_id`` or ``screen_name`` parameter.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/show Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-show
""" """
return self.get('users/show', params=params) return self.get('users/show', params=params)
@ -580,7 +631,8 @@ class EndpointsMixin(object):
"""Provides a simple, relevance-based search interface to public user """Provides a simple, relevance-based search interface to public user
accounts on Twitter. accounts on Twitter.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/search Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search
""" """
return self.get('users/search', params=params) return self.get('users/search', params=params)
@ -606,7 +658,7 @@ class EndpointsMixin(object):
Returns HTTP 200 upon success. Returns HTTP 200 upon success.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-remove_profile_banner
""" """
return self.post('account/remove_profile_banner', params=params) return self.post('account/remove_profile_banner', params=params)
@ -615,7 +667,7 @@ class EndpointsMixin(object):
"""Uploads a profile banner on behalf of the authenticating user. """Uploads a profile banner on behalf of the authenticating user.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner
""" """
return self.post('account/update_profile_background_image', return self.post('account/update_profile_background_image',
@ -625,7 +677,8 @@ class EndpointsMixin(object):
"""Returns a map of the available size variations of the specified """Returns a map of the available size variations of the specified
user's profile banner. user's profile banner.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/profile_banner Docs:
https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-users-profile_banner
""" """
return self.get('users/profile_banner', params=params) return self.get('users/profile_banner', params=params)
@ -634,7 +687,8 @@ class EndpointsMixin(object):
"""Returns a collection of user objects that the authenticating user """Returns a collection of user objects that the authenticating user
is muting. is muting.
Docs: https://dev.twitter.com/docs/api/1.1/get/mutes/users/list Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-list
""" """
return self.get('mutes/users/list', params=params) return self.get('mutes/users/list', params=params)
@ -645,7 +699,8 @@ class EndpointsMixin(object):
"""Returns an array of numeric user ids the authenticating user """Returns an array of numeric user ids the authenticating user
is muting. is muting.
Docs: https://dev.twitter.com/docs/api/1.1/get/mutes/users/ids Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-ids
""" """
return self.get('mutes/users/ids', params=params) return self.get('mutes/users/ids', params=params)
@ -656,16 +711,18 @@ class EndpointsMixin(object):
"""Mutes the specified user, preventing their tweets appearing """Mutes the specified user, preventing their tweets appearing
in the authenticating user's timeline. in the authenticating user's timeline.
Docs: https://dev.twitter.com/docs/api/1.1/post/mutes/users/create Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-create
""" """
return self.post('mutes/users/create', params=params) return self.post('mutes/users/create', params=params)
def destroy_mute(self, **params): def destroy_mute(self, **params):
"""Un-mutes the user specified in the user or ID parameter for """Un-mutes the user specified in the user or ``id`` parameter for
the authenticating user. the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/mutes/users/destroy Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-destroy
""" """
return self.post('mutes/users/destroy', params=params) return self.post('mutes/users/destroy', params=params)
@ -675,7 +732,7 @@ class EndpointsMixin(object):
"""Access the users in a given category of the Twitter suggested user list. """Access the users in a given category of the Twitter suggested user list.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-suggestions-slug
""" """
return self.get('users/suggestions/%s' % params.get('slug'), return self.get('users/suggestions/%s' % params.get('slug'),
@ -684,7 +741,8 @@ class EndpointsMixin(object):
def get_user_suggestions(self, **params): def get_user_suggestions(self, **params):
"""Access to Twitter's suggested user list. """Access to Twitter's suggested user list.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions Docs:
https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-suggestions
""" """
return self.get('users/suggestions', params=params) return self.get('users/suggestions', params=params)
@ -695,7 +753,7 @@ class EndpointsMixin(object):
user. user.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug/members https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-suggestions-slug-members
""" """
return self.get('users/suggestions/%s/members' % params.get('slug'), return self.get('users/suggestions/%s/members' % params.get('slug'),
@ -706,26 +764,29 @@ class EndpointsMixin(object):
"""Returns the 20 most recent Tweets favorited by the authenticating """Returns the 20 most recent Tweets favorited by the authenticating
or specified user. or specified user.
Docs: https://dev.twitter.com/docs/api/1.1/get/favorites/list Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-favorites-list
""" """
return self.get('favorites/list', params=params) return self.get('favorites/list', params=params)
get_favorites.iter_mode = 'id' get_favorites.iter_mode = 'id'
def destroy_favorite(self, **params): def destroy_favorite(self, **params):
"""Un-favorites the status specified in the ID parameter as the """Un-favorites the status specified in the ``id`` parameter as the
authenticating user. authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/favorites/destroy Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy
""" """
return self.post('favorites/destroy', params=params) return self.post('favorites/destroy', params=params)
def create_favorite(self, **params): def create_favorite(self, **params):
"""Favorites the status specified in the ID parameter as the """Favorites the status specified in the ``id`` parameter as the
authenticating user. authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/favorites/create Docs:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-create
""" """
return self.post('favorites/create', params=params) return self.post('favorites/create', params=params)
@ -735,7 +796,8 @@ class EndpointsMixin(object):
"""Returns all lists the authenticating or specified user subscribes to, """Returns all lists the authenticating or specified user subscribes to,
including their own. including their own.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/list Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-list
""" """
return self.get('lists/list', params=params) return self.get('lists/list', params=params)
@ -743,7 +805,8 @@ class EndpointsMixin(object):
def get_list_statuses(self, **params): def get_list_statuses(self, **params):
"""Returns a timeline of tweets authored by members of the specified list. """Returns a timeline of tweets authored by members of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/statuses Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-statuses
""" """
return self.get('lists/statuses', params=params) return self.get('lists/statuses', params=params)
@ -752,7 +815,8 @@ class EndpointsMixin(object):
def delete_list_member(self, **params): def delete_list_member(self, **params):
"""Removes the specified member from the list. """Removes the specified member from the list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy
""" """
return self.post('lists/members/destroy', params=params) return self.post('lists/members/destroy', params=params)
@ -760,7 +824,8 @@ class EndpointsMixin(object):
def get_list_memberships(self, **params): def get_list_memberships(self, **params):
"""Returns the lists the specified user has been added to. """Returns the lists the specified user has been added to.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/memberships Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-memberships
""" """
return self.get('lists/memberships', params=params) return self.get('lists/memberships', params=params)
@ -770,7 +835,8 @@ class EndpointsMixin(object):
def get_list_subscribers(self, **params): def get_list_subscribers(self, **params):
"""Returns the subscribers of the specified list. """Returns the subscribers of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/subscribers Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers
""" """
return self.get('lists/subscribers', params=params) return self.get('lists/subscribers', params=params)
@ -781,7 +847,7 @@ class EndpointsMixin(object):
"""Subscribes the authenticated user to the specified list. """Subscribes the authenticated user to the specified list.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-create
""" """
return self.post('lists/subscribers/create', params=params) return self.post('lists/subscribers/create', params=params)
@ -789,7 +855,8 @@ class EndpointsMixin(object):
def is_list_subscriber(self, **params): def is_list_subscriber(self, **params):
"""Check if the specified user is a subscriber of the specified list. """Check if the specified user is a subscriber of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers-show
""" """
return self.get('lists/subscribers/show', params=params) return self.get('lists/subscribers/show', params=params)
@ -798,7 +865,7 @@ class EndpointsMixin(object):
"""Unsubscribes the authenticated user from the specified list. """Unsubscribes the authenticated user from the specified list.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-destroy
""" """
return self.post('lists/subscribers/destroy', params=params) return self.post('lists/subscribers/destroy', params=params)
@ -808,7 +875,7 @@ class EndpointsMixin(object):
list of member ids or screen names. list of member ids or screen names.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all
""" """
return self.post('lists/members/create_all', params=params) return self.post('lists/members/create_all', params=params)
@ -816,7 +883,8 @@ class EndpointsMixin(object):
def is_list_member(self, **params): def is_list_member(self, **params):
"""Check if the specified user is a member of the specified list. """Check if the specified user is a member of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/members/show Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-members-show
""" """
return self.get('lists/members/show', params=params) return self.get('lists/members/show', params=params)
@ -824,7 +892,8 @@ class EndpointsMixin(object):
def get_list_members(self, **params): def get_list_members(self, **params):
"""Returns the members of the specified list. """Returns the members of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/members Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-members
""" """
return self.get('lists/members', params=params) return self.get('lists/members', params=params)
@ -834,7 +903,8 @@ class EndpointsMixin(object):
def add_list_member(self, **params): def add_list_member(self, **params):
"""Add a member to a list. """Add a member to a list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/members/create Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create
""" """
return self.post('lists/members/create', params=params) return self.post('lists/members/create', params=params)
@ -842,7 +912,8 @@ class EndpointsMixin(object):
def delete_list(self, **params): def delete_list(self, **params):
"""Deletes the specified list. """Deletes the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/destroy Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-destroy
""" """
return self.post('lists/destroy', params=params) return self.post('lists/destroy', params=params)
@ -850,7 +921,8 @@ class EndpointsMixin(object):
def update_list(self, **params): def update_list(self, **params):
"""Updates the specified list. """Updates the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/update Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-update
""" """
return self.post('lists/update', params=params) return self.post('lists/update', params=params)
@ -858,7 +930,8 @@ class EndpointsMixin(object):
def create_list(self, **params): def create_list(self, **params):
"""Creates a new list for the authenticated user. """Creates a new list for the authenticated user.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/create Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-create
""" """
return self.post('lists/create', params=params) return self.post('lists/create', params=params)
@ -866,7 +939,8 @@ class EndpointsMixin(object):
def get_specific_list(self, **params): def get_specific_list(self, **params):
"""Returns the specified list. """Returns the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/show Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-show
""" """
return self.get('lists/show', params=params) return self.get('lists/show', params=params)
@ -874,7 +948,8 @@ class EndpointsMixin(object):
def get_list_subscriptions(self, **params): def get_list_subscriptions(self, **params):
"""Obtain a collection of the lists the specified user is subscribed to. """Obtain a collection of the lists the specified user is subscribed to.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions
""" """
return self.get('lists/subscriptions', params=params) return self.get('lists/subscriptions', params=params)
@ -886,7 +961,7 @@ class EndpointsMixin(object):
comma-separated list of member ids or screen names. comma-separated list of member ids or screen names.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy_all
""" """
return self.post('lists/members/destroy_all', params=params) return self.post('lists/members/destroy_all', params=params)
@ -894,7 +969,8 @@ class EndpointsMixin(object):
def show_owned_lists(self, **params): def show_owned_lists(self, **params):
"""Returns the lists owned by the specified Twitter user. """Returns the lists owned by the specified Twitter user.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/ownerships Docs:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships
""" """
return self.get('lists/ownerships', params=params) return self.get('lists/ownerships', params=params)
@ -905,16 +981,17 @@ class EndpointsMixin(object):
def get_saved_searches(self, **params): def get_saved_searches(self, **params):
"""Returns the authenticated user's saved search queries. """Returns the authenticated user's saved search queries.
Docs: https://dev.twitter.com/docs/api/1.1/get/saved_searches/list Docs:
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-saved_searches-list
""" """
return self.get('saved_searches/list', params=params) return self.get('saved_searches/list', params=params)
def show_saved_search(self, **params): def show_saved_search(self, **params):
"""Retrieve the information for the saved search represented by the given id. """Retrieve the information for the saved search represented by the given ``id``.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/%3Aid https://developer.twitter.com/en/docs/tweets/search/api-reference/get-saved_searches-show-id
""" """
return self.get('saved_searches/show/%s' % params.get('id'), return self.get('saved_searches/show/%s' % params.get('id'),
@ -923,7 +1000,8 @@ class EndpointsMixin(object):
def create_saved_search(self, **params): def create_saved_search(self, **params):
"""Create a new saved search for the authenticated user. """Create a new saved search for the authenticated user.
Docs: https://dev.twitter.com/docs/api/1.1/post/saved_searches/create Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-create
""" """
return self.post('saved_searches/create', params=params) return self.post('saved_searches/create', params=params)
@ -932,7 +1010,7 @@ class EndpointsMixin(object):
"""Destroys a saved search for the authenticating user. """Destroys a saved search for the authenticating user.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/%3Aid https://developer.twitter.com/en/docs/tweets/search/api-reference/post-saved_searches-destroy-id
""" """
return self.post('saved_searches/destroy/%s' % params.get('id'), return self.post('saved_searches/destroy/%s' % params.get('id'),
@ -942,7 +1020,8 @@ class EndpointsMixin(object):
def get_geo_info(self, **params): def get_geo_info(self, **params):
"""Returns all the information about a known place. """Returns all the information about a known place.
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/id/%3Aplace_id Docs:
https://developer.twitter.com/en/docs/geo/place-information/api-reference/get-geo-id-place_id
""" """
return self.get('geo/id/%s' % params.get('place_id'), params=params) return self.get('geo/id/%s' % params.get('place_id'), params=params)
@ -951,7 +1030,8 @@ class EndpointsMixin(object):
"""Given a latitude and a longitude, searches for up to 20 places """Given a latitude and a longitude, searches for up to 20 places
that can be used as a place_id when updating a status. that can be used as a place_id when updating a status.
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode Docs:
https://developer.twitter.com/en/docs/geo/places-near-location/api-reference/get-geo-reverse_geocode
""" """
return self.get('geo/reverse_geocode', params=params) return self.get('geo/reverse_geocode', params=params)
@ -959,7 +1039,8 @@ class EndpointsMixin(object):
def search_geo(self, **params): def search_geo(self, **params):
"""Search for places that can be attached to a statuses/update. """Search for places that can be attached to a statuses/update.
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/search Docs:
https://developer.twitter.com/en/docs/geo/places-near-location/api-reference/get-geo-search
""" """
return self.get('geo/search', params=params) return self.get('geo/search', params=params)
@ -985,7 +1066,8 @@ class EndpointsMixin(object):
"""Returns the top 10 trending topics for a specific WOEID, if """Returns the top 10 trending topics for a specific WOEID, if
trending information is available for it. trending information is available for it.
Docs: https://dev.twitter.com/docs/api/1.1/get/trends/place Docs:
https://developer.twitter.com/en/docs/trends/trends-for-location/api-reference/get-trends-place
""" """
return self.get('trends/place', params=params) return self.get('trends/place', params=params)
@ -993,7 +1075,8 @@ class EndpointsMixin(object):
def get_available_trends(self, **params): def get_available_trends(self, **params):
"""Returns the locations that Twitter has trending topic information for. """Returns the locations that Twitter has trending topic information for.
Docs: https://dev.twitter.com/docs/api/1.1/get/trends/available Docs:
https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-available
""" """
return self.get('trends/available', params=params) return self.get('trends/available', params=params)
@ -1002,7 +1085,8 @@ class EndpointsMixin(object):
"""Returns the locations that Twitter has trending topic information """Returns the locations that Twitter has trending topic information
for, closest to a specified location. for, closest to a specified location.
Docs: https://dev.twitter.com/docs/api/1.1/get/trends/closest Docs:
https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-closest
""" """
return self.get('trends/closest', params=params) return self.get('trends/closest', params=params)
@ -1011,7 +1095,8 @@ class EndpointsMixin(object):
def report_spam(self, **params): # pragma: no cover def report_spam(self, **params): # pragma: no cover
"""Report the specified user as a spam account to Twitter. """Report the specified user as a spam account to Twitter.
Docs: https://dev.twitter.com/docs/api/1.1/post/users/report_spam Docs:
https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-users-report_spam
""" """
return self.post('users/report_spam', params=params) return self.post('users/report_spam', params=params)
@ -1021,7 +1106,8 @@ class EndpointsMixin(object):
"""Allows a registered application to revoke an issued OAuth 2 Bearer """Allows a registered application to revoke an issued OAuth 2 Bearer
Token by presenting its client credentials. Token by presenting its client credentials.
Docs: https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token Docs:
https://developer.twitter.com/en/docs/basics/authentication/api-reference/invalidate_token
""" """
return self.post('oauth2/invalidate_token', params=params) return self.post('oauth2/invalidate_token', params=params)
@ -1030,7 +1116,8 @@ class EndpointsMixin(object):
def get_twitter_configuration(self, **params): def get_twitter_configuration(self, **params):
"""Returns the current configuration used by Twitter """Returns the current configuration used by Twitter
Docs: https://dev.twitter.com/docs/api/1.1/get/help/configuration Docs:
https://developer.twitter.com/en/docs/developer-utilities/configuration/api-reference/get-help-configuration
""" """
return self.get('help/configuration', params=params) return self.get('help/configuration', params=params)
@ -1039,7 +1126,8 @@ class EndpointsMixin(object):
"""Returns the list of languages supported by Twitter along with """Returns the list of languages supported by Twitter along with
their ISO 639-1 code. their ISO 639-1 code.
Docs: https://dev.twitter.com/docs/api/1.1/get/help/languages Docs:
https://developer.twitter.com/en/docs/developer-utilities/supported-languages/api-reference/get-help-languages
""" """
return self.get('help/languages', params=params) return self.get('help/languages', params=params)
@ -1047,7 +1135,8 @@ class EndpointsMixin(object):
def get_privacy_policy(self, **params): def get_privacy_policy(self, **params):
"""Returns Twitter's Privacy Policy """Returns Twitter's Privacy Policy
Docs: https://dev.twitter.com/docs/api/1.1/get/help/privacy Docs:
https://developer.twitter.com/en/docs/developer-utilities/privacy-policy/api-reference/get-help-privacy
""" """
return self.get('help/privacy', params=params) return self.get('help/privacy', params=params)
@ -1055,7 +1144,8 @@ class EndpointsMixin(object):
def get_tos(self, **params): def get_tos(self, **params):
"""Return the Twitter Terms of Service """Return the Twitter Terms of Service
Docs: https://dev.twitter.com/docs/api/1.1/get/help/tos Docs:
https://developer.twitter.com/en/docs/developer-utilities/terms-of-service/api-reference/get-help-tos
""" """
return self.get('help/tos', params=params) return self.get('help/tos', params=params)
@ -1065,13 +1155,13 @@ class EndpointsMixin(object):
specified resource families. specified resource families.
Docs: Docs:
https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status https://developer.twitter.com/en/docs/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status
""" """
return self.get('application/rate_limit_status', params=params) return self.get('application/rate_limit_status', params=params)
# from https://dev.twitter.com/docs/error-codes-responses # from https://developer.twitter.com/en/docs/ads/general/guides/response-codes
TWITTER_HTTP_STATUS_CODE = { TWITTER_HTTP_STATUS_CODE = {
200: ('OK', 'Success!'), 200: ('OK', 'Success!'),
304: ('Not Modified', 'There was no new data to return.'), 304: ('Not Modified', 'There was no new data to return.'),

View File

@ -169,9 +169,9 @@ class TwythonStreamer(object):
Returns True if other handlers for this message should be invoked. Returns True if other handlers for this message should be invoked.
Feel free to override this to handle your streaming data how you Feel free to override this to handle your streaming data how you
want it handled. want it handled. See
See https://dev.twitter.com/docs/streaming-apis/messages for messages https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/streaming-message-types
sent along in stream responses. for messages sent along in stream responses.
:param data: data recieved from the stream :param data: data recieved from the stream
:type data: dict :type data: dict

View File

@ -44,9 +44,10 @@ class TwythonStreamerTypes(object):
class TwythonStreamerTypesStatuses(object): class TwythonStreamerTypesStatuses(object):
"""Class for different statuses endpoints """Class for different statuses endpoints
Available so TwythonStreamer.statuses.filter() is available. Available so :meth:`TwythonStreamer.statuses.filter()` is available.
Just a bit cleaner than TwythonStreamer.statuses_filter(), Just a bit cleaner than :meth:`TwythonStreamer.statuses_filter()`,
statuses_sample(), etc. all being single methods in TwythonStreamer :meth:`statuses_sample()`, etc. all being single methods in
:class:`TwythonStreamer`.
""" """
def __init__(self, streamer): def __init__(self, streamer):
@ -59,7 +60,7 @@ class TwythonStreamerTypesStatuses(object):
:param \*\*params: Parameters to send with your stream request :param \*\*params: Parameters to send with your stream request
Accepted params found at: Accepted params found at:
https://dev.twitter.com/docs/api/1.1/post/statuses/filter https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter
""" """
url = 'https://stream.twitter.com/%s/statuses/filter.json' \ url = 'https://stream.twitter.com/%s/statuses/filter.json' \
% self.streamer.api_version % self.streamer.api_version
@ -71,7 +72,7 @@ class TwythonStreamerTypesStatuses(object):
:param \*\*params: Parameters to send with your stream request :param \*\*params: Parameters to send with your stream request
Accepted params found at: Accepted params found at:
https://dev.twitter.com/docs/api/1.1/get/statuses/sample https://developer.twitter.com/en/docs/tweets/sample-realtime/api-reference/get-statuses-sample
""" """
url = 'https://stream.twitter.com/%s/statuses/sample.json' \ url = 'https://stream.twitter.com/%s/statuses/sample.json' \
% self.streamer.api_version % self.streamer.api_version
@ -95,7 +96,7 @@ class TwythonStreamerTypesStatuses(object):
:param \*\*params: Parameters to send with your stream request :param \*\*params: Parameters to send with your stream request
Accepted params found at: Accepted params found at:
https://dev.twitter.com/docs/api/1.1/post/statuses/filter https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter
""" """
self.params = params self.params = params
@ -104,4 +105,4 @@ class TwythonStreamerTypesStatuses(object):
url = 'https://stream.twitter.com/%s/statuses/filter.json' \ url = 'https://stream.twitter.com/%s/statuses/filter.json' \
% self.streamer.api_version % self.streamer.api_version
self.streamer._request(url, 'POST', params=self.params) self.streamer._request(url, 'POST', params=self.params)