The endpoints that they use have been removed.
https://developer.twitter.com/en/updates/changelog
+++ /dev/null
-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
+++ /dev/null
-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
+--------------------------------------------------------------+--------------------------------------------------------+
| .. 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` |
.. _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
Blocks
------
-.. automethod:: AsyncClient.unblock
-
.. automethod:: AsyncClient.get_blocked
-.. automethod:: AsyncClient.block
-
Follows
-------
+------------------------------------------------------------------------------------------------------------------+
| .. 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` |
.. _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
Blocks
------
-.. automethod:: Client.unblock
-
.. automethod:: Client.get_blocked
-.. automethod:: Client.block
-
Follows
-------
# @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):
# @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):
.. versionadded:: 4.10
+ .. versionchanged:: 4.15
+ Removed ``block`` and ``unblock`` methods, as the endpoints they use
+ have been removed
+
Parameters
----------
bearer_token : str | None
# 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, \
), 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):
.. versionadded:: 4.0
+ .. versionchanged:: 4.15
+ Removed ``block`` and ``unblock`` methods, as the endpoints they use
+ have been removed
+
Parameters
----------
bearer_token : str | None
# 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, \
), 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):