From 12cc9fa337d483089bb3104bcbba1af93a821fa7 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 29 Jun 2023 16:45:03 -0500 Subject: [PATCH] Remove Client and AsyncClient block and unblock methods The endpoints that they use have been removed. https://developer.twitter.com/en/updates/changelog --- ...ent_block_and_get_blocked_and unblock.yaml | 185 ------------------ ...ent_block_and_get_blocked_and unblock.yaml | 183 ----------------- docs/asyncclient.rst | 10 - docs/client.rst | 10 - tests/test_asyncclient.py | 9 +- tests/test_client.py | 7 +- tweepy/asynchronous/client.py | 86 +------- tweepy/client.py | 100 +--------- 8 files changed, 10 insertions(+), 580 deletions(-) delete mode 100644 cassettes/test_asyncclient_block_and_get_blocked_and unblock.yaml delete mode 100644 cassettes/test_client_block_and_get_blocked_and unblock.yaml diff --git a/cassettes/test_asyncclient_block_and_get_blocked_and unblock.yaml b/cassettes/test_asyncclient_block_and_get_blocked_and unblock.yaml deleted file mode 100644 index 2cd4817..0000000 --- a/cassettes/test_asyncclient_block_and_get_blocked_and unblock.yaml +++ /dev/null @@ -1,185 +0,0 @@ -interactions: -- request: - body: - target_user_id: '17874544' - headers: - Content-Type: - - application/json - User-Agent: - - Python/3.10.0 aiohttp/3.7.4.post0 Tweepy/4.9.0 - method: POST - uri: https://api.twitter.com/2/users/1072250532645998596/blocking - response: - body: - string: '{"data":{"blocking":true}}' - headers: - api-version: - - '2.42' - cache-control: - - no-cache, no-store, max-age=0 - content-disposition: - - attachment; filename=json.json - content-encoding: - - gzip - content-length: - - '52' - content-type: - - application/json; charset=utf-8 - date: - - Sat, 07 May 2022 13:20:50 UTC - server: - - tsa_b - set-cookie: - - guest_id_marketing=v1%3A165192965087916447; Max-Age=63072000; Expires=Mon, - 06 May 2024 13:20:50 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id_ads=v1%3A165192965087916447; Max-Age=63072000; Expires=Mon, 06 May - 2024 13:20:50 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - personalization_id="v1_d6raK5hbnCFRKnII2kd5hQ=="; Max-Age=63072000; Expires=Mon, - 06 May 2024 13:20:50 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id=v1%3A165192965087916447; Max-Age=63072000; Expires=Mon, 06 May 2024 - 13:20:50 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - strict-transport-security: - - max-age=631138519 - x-access-level: - - read-write-directmessages - x-connection-hash: - - c9ce8c94ed937e66ed27655cc9cb540351079e5c38b952f0fe5622664320d42e - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rate-limit-limit: - - '50' - x-rate-limit-remaining: - - '49' - x-rate-limit-reset: - - '1651930550' - x-response-time: - - '41' - x-xss-protection: - - '0' - status: - code: 200 - message: OK - url: https://api.twitter.com/2/users/1072250532645998596/blocking -- request: - body: null - headers: - User-Agent: - - Python/3.10.0 aiohttp/3.7.4.post0 Tweepy/4.9.0 - method: GET - uri: https://api.twitter.com/2/users/1072250532645998596/blocking - response: - body: - string: '{"data":[{"id":"17874544","name":"Twitter Support","username":"TwitterSupport"}],"meta":{"result_count":1}}' - headers: - api-version: - - '2.42' - cache-control: - - no-cache, no-store, max-age=0 - content-disposition: - - attachment; filename=json.json - content-encoding: - - gzip - content-length: - - '111' - content-type: - - application/json; charset=utf-8 - date: - - Sat, 07 May 2022 13:20:51 UTC - server: - - tsa_b - set-cookie: - - guest_id_marketing=v1%3A165192965103954945; Max-Age=63072000; Expires=Mon, - 06 May 2024 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id_ads=v1%3A165192965103954945; Max-Age=63072000; Expires=Mon, 06 May - 2024 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - personalization_id="v1_i17sy7cUDAjsGIpFEiP82w=="; Max-Age=63072000; Expires=Mon, - 06 May 2024 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id=v1%3A165192965103954945; Max-Age=63072000; Expires=Mon, 06 May 2024 - 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - strict-transport-security: - - max-age=631138519 - x-access-level: - - read-write-directmessages - x-connection-hash: - - 6518b1ea1eedc55716aea9d3c3a7c13005142dd0edca34f50821728bda86965a - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rate-limit-limit: - - '15' - x-rate-limit-remaining: - - '14' - x-rate-limit-reset: - - '1651930551' - x-response-time: - - '42' - x-xss-protection: - - '0' - status: - code: 200 - message: OK - url: https://api.twitter.com/2/users/1072250532645998596/blocking -- request: - body: null - headers: - User-Agent: - - Python/3.10.0 aiohttp/3.7.4.post0 Tweepy/4.9.0 - method: DELETE - uri: https://api.twitter.com/2/users/1072250532645998596/blocking/17874544 - response: - body: - string: '{"data":{"blocking":false}}' - headers: - api-version: - - '2.42' - cache-control: - - no-cache, no-store, max-age=0 - content-disposition: - - attachment; filename=json.json - content-encoding: - - gzip - content-length: - - '53' - content-type: - - application/json; charset=utf-8 - date: - - Sat, 07 May 2022 13:20:51 UTC - server: - - tsa_b - set-cookie: - - guest_id_marketing=v1%3A165192965123045517; Max-Age=63072000; Expires=Mon, - 06 May 2024 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id_ads=v1%3A165192965123045517; Max-Age=63072000; Expires=Mon, 06 May - 2024 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - personalization_id="v1_VeY7KCW087dRYotZqyA/ig=="; Max-Age=63072000; Expires=Mon, - 06 May 2024 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id=v1%3A165192965123045517; Max-Age=63072000; Expires=Mon, 06 May 2024 - 13:20:51 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - strict-transport-security: - - max-age=631138519 - x-access-level: - - read-write-directmessages - x-connection-hash: - - 4e0af34f12925ee64848c60af7be02d98e38b2ee16eb71e16465cab2c32def2a - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rate-limit-limit: - - '50' - x-rate-limit-remaining: - - '49' - x-rate-limit-reset: - - '1651930551' - x-response-time: - - '38' - x-xss-protection: - - '0' - status: - code: 200 - message: OK - url: https://api.twitter.com/2/users/1072250532645998596/blocking/17874544 -version: 1 diff --git a/cassettes/test_client_block_and_get_blocked_and unblock.yaml b/cassettes/test_client_block_and_get_blocked_and unblock.yaml deleted file mode 100644 index ea8d39f..0000000 --- a/cassettes/test_client_block_and_get_blocked_and unblock.yaml +++ /dev/null @@ -1,183 +0,0 @@ -interactions: -- request: - body: '{"target_user_id": "17874544"}' - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Length: - - '30' - Content-Type: - - application/json - User-Agent: - - Python/3.9.6 Requests/2.25.1 Tweepy/4.0.0-alpha - method: POST - uri: https://api.twitter.com/2/users/1072250532645998596/blocking - response: - body: - string: !!binary | - H4sIAAAAAAAAAKpWSkksSVSyqlZKyslPzs7MS1eyKikqTa2tBQAAAP//AwBcCHSuGgAAAA== - headers: - api-version: - - '2.24' - cache-control: - - no-cache, no-store, max-age=0 - content-disposition: - - attachment; filename=json.json - content-encoding: - - gzip - content-length: - - '52' - content-type: - - application/json; charset=utf-8 - date: - - Mon, 20 Sep 2021 18:12:41 UTC - server: - - tsa_b - set-cookie: - - personalization_id="v1_YP58GZ7KULovj9I0BZd+tA=="; Max-Age=63072000; Expires=Wed, - 20 Sep 2023 18:12:41 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - - guest_id=v1%3A163216156123071343; Max-Age=63072000; Expires=Wed, 20 Sep 2023 - 18:12:41 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None - strict-transport-security: - - max-age=631138519 - x-access-level: - - read-write-directmessages - x-connection-hash: - - 74daf3f6996e83c2a3a1336df68a70c9ffe266db5ca7f75f44b223f3b021bc79 - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rate-limit-limit: - - '50' - x-rate-limit-remaining: - - '49' - x-rate-limit-reset: - - '1632162461' - x-xss-protection: - - '0' - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Cookie: - - guest_id=v1%3A163216156123071343; personalization_id="v1_YP58GZ7KULovj9I0BZd+tA==" - User-Agent: - - Python/3.9.6 Requests/2.25.1 Tweepy/4.0.0-alpha - method: GET - uri: https://api.twitter.com/2/users/1072250532645998596/blocking - response: - body: - string: !!binary | - H4sIAAAAAAAAAKpWSkksSVSyiq5WykxRslIyNLcwNzE1MVHSUcpLzE0FioSUZ5aUpBYpBJcWFOQX - lQAlSotTi1AlYXK1sTpKuakg86qVilKLS3NK4pPzS/NKlKwMa2sBAAAA//8DAMW+VFVrAAAA - headers: - api-version: - - '2.24' - cache-control: - - no-cache, no-store, max-age=0 - content-disposition: - - attachment; filename=json.json - content-encoding: - - gzip - content-length: - - '111' - content-type: - - application/json; charset=utf-8 - date: - - Mon, 20 Sep 2021 18:12:41 UTC - server: - - tsa_b - strict-transport-security: - - max-age=631138519 - x-access-level: - - read-write-directmessages - x-connection-hash: - - 74daf3f6996e83c2a3a1336df68a70c9ffe266db5ca7f75f44b223f3b021bc79 - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rate-limit-limit: - - '15' - x-rate-limit-remaining: - - '14' - x-rate-limit-reset: - - '1632162461' - x-xss-protection: - - '0' - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Length: - - '0' - Cookie: - - guest_id=v1%3A163216156123071343; personalization_id="v1_YP58GZ7KULovj9I0BZd+tA==" - User-Agent: - - Python/3.9.6 Requests/2.25.1 Tweepy/4.0.0-alpha - method: DELETE - uri: https://api.twitter.com/2/users/1072250532645998596/blocking/17874544 - response: - body: - string: !!binary | - H4sIAAAAAAAAAKpWSkksSVSyqlZKyslPzs7MS1eySkvMKU6trQUAAAD//wMAcXlx4RsAAAA= - headers: - api-version: - - '2.24' - cache-control: - - no-cache, no-store, max-age=0 - content-disposition: - - attachment; filename=json.json - content-encoding: - - gzip - content-length: - - '53' - content-type: - - application/json; charset=utf-8 - date: - - Mon, 20 Sep 2021 18:12:41 UTC - server: - - tsa_b - strict-transport-security: - - max-age=631138519 - x-access-level: - - read-write-directmessages - x-connection-hash: - - 74daf3f6996e83c2a3a1336df68a70c9ffe266db5ca7f75f44b223f3b021bc79 - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rate-limit-limit: - - '50' - x-rate-limit-remaining: - - '49' - x-rate-limit-reset: - - '1632162461' - x-xss-protection: - - '0' - status: - code: 200 - message: OK -version: 1 diff --git a/docs/asyncclient.rst b/docs/asyncclient.rst index 0f9f0f6..4458308 100644 --- a/docs/asyncclient.rst +++ b/docs/asyncclient.rst @@ -88,12 +88,8 @@ +--------------------------------------------------------------+--------------------------------------------------------+ | .. centered:: |Blocks|_ | +--------------------------------------------------------------+--------------------------------------------------------+ - | `DELETE /2/users/:source_user_id/blocking/:target_user_id`_ | :meth:`AsyncClient.unblock` | - +--------------------------------------------------------------+--------------------------------------------------------+ | `GET /2/users/:id/blocking`_ | :meth:`AsyncClient.get_blocked` | +--------------------------------------------------------------+--------------------------------------------------------+ - | `POST /2/users/:id/blocking`_ | :meth:`AsyncClient.block` | - +--------------------------------------------------------------+--------------------------------------------------------+ | .. centered:: |Follows|_ | +--------------------------------------------------------------+--------------------------------------------------------+ | `DELETE /2/users/:source_user_id/following/:target_user_id`_ | :meth:`AsyncClient.unfollow_user` | @@ -253,9 +249,7 @@ .. _GET /2/tweets/:id: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id .. _GET /2/tweets: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets .. |Blocks| replace:: *Blocks* -.. _DELETE /2/users/:source_user_id/blocking/:target_user_id: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking .. _GET /2/users/:id/blocking: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking -.. _POST /2/users/:id/blocking: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking .. |Follows| replace:: *Follows* .. _DELETE /2/users/:source_user_id/following/:target_user_id: https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following .. _GET /2/users/:id/followers: https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers @@ -402,12 +396,8 @@ Users Blocks ------ -.. automethod:: AsyncClient.unblock - .. automethod:: AsyncClient.get_blocked -.. automethod:: AsyncClient.block - Follows ------- diff --git a/docs/client.rst b/docs/client.rst index a32ac22..2fec1b6 100644 --- a/docs/client.rst +++ b/docs/client.rst @@ -88,12 +88,8 @@ +------------------------------------------------------------------------------------------------------------------+ | .. centered:: |Blocks|_ | +--------------------------------------------------------------+---------------------------------------------------+ - | `DELETE /2/users/:source_user_id/blocking/:target_user_id`_ | :meth:`Client.unblock` | - +--------------------------------------------------------------+---------------------------------------------------+ | `GET /2/users/:id/blocking`_ | :meth:`Client.get_blocked` | +--------------------------------------------------------------+---------------------------------------------------+ - | `POST /2/users/:id/blocking`_ | :meth:`Client.block` | - +--------------------------------------------------------------+---------------------------------------------------+ | .. centered:: |Follows|_ | +--------------------------------------------------------------+---------------------------------------------------+ | `DELETE /2/users/:source_user_id/following/:target_user_id`_ | :meth:`Client.unfollow_user` | @@ -253,9 +249,7 @@ .. _GET /2/tweets/:id: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id .. _GET /2/tweets: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets .. |Blocks| replace:: *Blocks* -.. _DELETE /2/users/:source_user_id/blocking/:target_user_id: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking .. _GET /2/users/:id/blocking: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking -.. _POST /2/users/:id/blocking: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking .. |Follows| replace:: *Follows* .. _DELETE /2/users/:source_user_id/following/:target_user_id: https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following .. _GET /2/users/:id/followers: https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers @@ -402,12 +396,8 @@ Users Blocks ------ -.. automethod:: Client.unblock - .. automethod:: Client.get_blocked -.. automethod:: Client.block - Follows ------- diff --git a/tests/test_asyncclient.py b/tests/test_asyncclient.py index f7fa1b8..0523603 100644 --- a/tests/test_asyncclient.py +++ b/tests/test_asyncclient.py @@ -114,14 +114,7 @@ class TweepyAsyncClientTests(IsolatedAsyncioTestCase): # @TwitterDev and @TwitterAPI Tweets announcing API v2 await self.client.get_tweets(tweet_ids) - @tape.use_cassette( - "test_asyncclient_block_and_get_blocked_and unblock.yaml" - ) - async def test_block_and_get_blocked_and_unblock(self): - user_id = 17874544 # User ID for @TwitterSupport - await self.client.block(user_id) - await self.client.get_blocked() - await self.client.unblock(user_id) + # TODO: Test AsyncClient.get_blocked @tape.use_cassette("test_asyncclient_follow_and_unfollow_user.yaml") async def test_follow_and_unfollow_user(self): diff --git a/tests/test_client.py b/tests/test_client.py index faa3a41..3240a3a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -110,12 +110,7 @@ class TweepyClientTests(unittest.TestCase): # @TwitterDev and @TwitterAPI Tweets announcing API v2 self.client.get_tweets(tweet_ids) - @tape.use_cassette("test_client_block_and_get_blocked_and unblock.yaml") - def test_block_and_get_blocked_and_unblock(self): - user_id = 17874544 # User ID for @TwitterSupport - self.client.block(user_id) - self.client.get_blocked() - self.client.unblock(user_id) + # TODO: Test Client.get_blocked @tape.use_cassette("test_client_follow_and_unfollow_user.yaml") def test_follow_and_unfollow_user(self): diff --git a/tweepy/asynchronous/client.py b/tweepy/asynchronous/client.py index 9eb001d..312332a 100644 --- a/tweepy/asynchronous/client.py +++ b/tweepy/asynchronous/client.py @@ -169,6 +169,10 @@ class AsyncClient(AsyncBaseClient): .. versionadded:: 4.10 + .. versionchanged:: 4.15 + Removed ``block`` and ``unblock`` methods, as the endpoints they use + have been removed + Parameters ---------- bearer_token : str | None @@ -1719,49 +1723,6 @@ class AsyncClient(AsyncBaseClient): # Blocks - async def unblock(self, target_user_id, *, user_auth=True): - """Unblock another user. - - The request succeeds with no action when the user sends a request to a - user they're not blocking or have already unblocked. - - .. note:: - - When using OAuth 2.0 Authorization Code Flow with PKCE with - ``user_auth=False``, a request is made beforehand to Twitter's API - to determine the authenticating user's ID. This is cached and only - done once per :class:`AsyncClient` instance for each access token - used. - - Parameters - ---------- - target_user_id : int | str - The user ID of the user that you would like to unblock. - user_auth : bool - Whether or not to use OAuth 1.0a User Context to authenticate - - Raises - ------ - TypeError - If the access token isn't set - - Returns - ------- - dict | aiohttp.ClientResponse | Response - - References - ---------- - https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking - """ - source_user_id = await self._get_authenticating_user_id( - oauth_1=user_auth - ) - route = f"/2/users/{source_user_id}/blocking/{target_user_id}" - - return await self._make_request( - "DELETE", route, user_auth=user_auth - ) - async def get_blocked(self, *, user_auth=True, **params): """get_blocked( \ *, expansions=None, max_results=None, pagination_token=None, \ @@ -1821,45 +1782,6 @@ class AsyncClient(AsyncBaseClient): ), data_type=User, user_auth=user_auth ) - async def block(self, target_user_id, *, user_auth=True): - """Block another user. - - .. note:: - - When using OAuth 2.0 Authorization Code Flow with PKCE with - ``user_auth=False``, a request is made beforehand to Twitter's API - to determine the authenticating user's ID. This is cached and only - done once per :class:`AsyncClient` instance for each access token - used. - - Parameters - ---------- - target_user_id : int | str - The user ID of the user that you would like to block. - user_auth : bool - Whether or not to use OAuth 1.0a User Context to authenticate - - Raises - ------ - TypeError - If the access token isn't set - - Returns - ------- - dict | aiohttp.ClientResponse | Response - - References - ---------- - https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking - """ - id = await self._get_authenticating_user_id(oauth_1=user_auth) - route = f"/2/users/{id}/blocking" - - return await self._make_request( - "POST", route, json={"target_user_id": str(target_user_id)}, - user_auth=user_auth - ) - # Follows async def unfollow_user(self, target_user_id, *, user_auth=True): diff --git a/tweepy/client.py b/tweepy/client.py index 440a155..1217386 100644 --- a/tweepy/client.py +++ b/tweepy/client.py @@ -211,6 +211,10 @@ class Client(BaseClient): .. versionadded:: 4.0 + .. versionchanged:: 4.15 + Removed ``block`` and ``unblock`` methods, as the endpoints they use + have been removed + Parameters ---------- bearer_token : str | None @@ -1828,55 +1832,6 @@ class Client(BaseClient): # Blocks - def unblock(self, target_user_id, *, user_auth=True): - """Unblock another user. - - The request succeeds with no action when the user sends a request to a - user they're not blocking or have already unblocked. - - .. note:: - - When using OAuth 2.0 Authorization Code Flow with PKCE with - ``user_auth=False``, a request is made beforehand to Twitter's API - to determine the authenticating user's ID. This is cached and only - done once per :class:`Client` instance for each access token used. - - .. versionchanged:: 4.5 - Added ``user_auth`` parameter - - .. versionchanged:: 4.8 - Added support for using OAuth 2.0 Authorization Code Flow with PKCE - - .. versionchanged:: 4.8 - Changed to raise :class:`TypeError` when the access token isn't set - - Parameters - ---------- - target_user_id : int | str - The user ID of the user that you would like to unblock. - user_auth : bool - Whether or not to use OAuth 1.0a User Context to authenticate - - Raises - ------ - TypeError - If the access token isn't set - - Returns - ------- - dict | requests.Response | Response - - References - ---------- - https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking - """ - source_user_id = self._get_authenticating_user_id(oauth_1=user_auth) - route = f"/2/users/{source_user_id}/blocking/{target_user_id}" - - return self._make_request( - "DELETE", route, user_auth=user_auth - ) - def get_blocked(self, *, user_auth=True, **params): """get_blocked( \ *, expansions=None, max_results=None, pagination_token=None, \ @@ -1944,53 +1899,6 @@ class Client(BaseClient): ), data_type=User, user_auth=user_auth ) - def block(self, target_user_id, *, user_auth=True): - """Block another user. - - .. note:: - - When using OAuth 2.0 Authorization Code Flow with PKCE with - ``user_auth=False``, a request is made beforehand to Twitter's API - to determine the authenticating user's ID. This is cached and only - done once per :class:`Client` instance for each access token used. - - .. versionchanged:: 4.5 - Added ``user_auth`` parameter - - .. versionchanged:: 4.8 - Added support for using OAuth 2.0 Authorization Code Flow with PKCE - - .. versionchanged:: 4.8 - Changed to raise :class:`TypeError` when the access token isn't set - - Parameters - ---------- - target_user_id : int | str - The user ID of the user that you would like to block. - user_auth : bool - Whether or not to use OAuth 1.0a User Context to authenticate - - Raises - ------ - TypeError - If the access token isn't set - - Returns - ------- - dict | requests.Response | Response - - References - ---------- - https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking - """ - id = self._get_authenticating_user_id(oauth_1=user_auth) - route = f"/2/users/{id}/blocking" - - return self._make_request( - "POST", route, json={"target_user_id": str(target_user_id)}, - user_auth=user_auth - ) - # Follows def unfollow_user(self, target_user_id, *, user_auth=True): -- 2.25.1