From c8d5d9ad2c2b3c6b58b987286726cad467ce888f Mon Sep 17 00:00:00 2001 From: Harmon Date: Sat, 19 Feb 2022 18:32:31 -0600 Subject: [PATCH] Add Client.get_space_tweets --- docs/client.rst | 5 +++++ tests/test_client.py | 2 ++ tweepy/client.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/docs/client.rst b/docs/client.rst index b6dc18f..75865ea 100644 --- a/docs/client.rst +++ b/docs/client.rst @@ -124,6 +124,8 @@ +--------------------------------------------------------------+----------------------------------------+ | `GET /2/spaces/:id/buyers`_ | :meth:`Client.get_space_buyers` | +--------------------------------------------------------------+----------------------------------------+ + | `GET /2/spaces/:id/tweets`_ | :meth:`Client.get_space_tweets` | + +--------------------------------------------------------------+----------------------------------------+ | `GET /2/spaces/by/creator_ids`_ | :meth:`Client.get_spaces` | +--------------------------------------------------------------+----------------------------------------+ | .. centered:: :ref:`Lists` | @@ -236,6 +238,7 @@ .. _GET /2/spaces: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces .. _GET /2/spaces/:id: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id .. _GET /2/spaces/:id/buyers: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers +.. _GET /2/spaces/:id/tweets: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-tweets .. _GET /2/spaces/by/creator_ids: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids .. |List Tweets lookup| replace:: *List Tweets lookup* .. _GET /2/lists/:id/tweets: https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets @@ -392,6 +395,8 @@ Spaces lookup .. automethod:: Client.get_space_buyers +.. automethod:: Client.get_space_tweets + Lists ===== diff --git a/tests/test_client.py b/tests/test_client.py index 36b35ba..e3197cc 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -160,6 +160,8 @@ class TweepyTestCase(unittest.TestCase): # TODO: Test Client.get_space_buyers + # TODO: Test Client.get_space_tweets + @tape.use_cassette("test_get_list_tweets.yaml", serializer="yaml") def test_get_list_tweets(self): list_id = 84839422 # List ID for Official Twitter Accounts (@Twitter) diff --git a/tweepy/client.py b/tweepy/client.py index 5854d1f..1af2c74 100644 --- a/tweepy/client.py +++ b/tweepy/client.py @@ -2083,6 +2083,48 @@ class Client: ), data_type=User ) + def get_space_tweets(self, id, **params): + """get_space_tweets(id, *, expansions, media_fields, place_fields, \ + poll_fields, tweet_fields, user_fields) + + Returns Tweets shared in the requested Spaces. + + .. versionadded:: 4.6 + + Parameters + ---------- + id : str + Unique identifier of the Space containing the Tweets you'd like to + access. + expansions : Union[List[str], str] + :ref:`expansions_parameter` + media_fields : Union[List[str], str] + :ref:`media_fields_parameter` + place_fields : Union[List[str], str] + :ref:`place_fields_parameter` + poll_fields : Union[List[str], str] + :ref:`poll_fields_parameter` + tweet_fields : Union[List[str], str] + :ref:`tweet_fields_parameter` + user_fields : Union[List[str], str] + :ref:`user_fields_parameter` + + Returns + ------- + Union[dict, requests.Response, Response] + + References + ---------- + https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-tweets + """ + return self._make_request( + "GET", f"/2/spaces/{id}/tweets", params=params, + endpoint_parameters=( + "expansions", "media.fields", "place.fields", "poll.fields", + "tweet.fields", "user.fields" + ), data_type=Tweet + ) + # List Tweets lookup def get_list_tweets(self, id, *, user_auth=False, **params): -- 2.25.1