--- /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/muting
+ response:
+ body:
+ string: !!binary |
+ H4sIAAAAAAAAAKpWSkksSVSyqlbKLS3JzEtXsiopKk2trQUAAAD//wMAKOKMLRgAAAA=
+ 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:
+ - '50'
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Mon, 20 Sep 2021 21:47:48 UTC
+ server:
+ - tsa_a
+ set-cookie:
+ - personalization_id="v1_tx5lZdBKqUcj82GIzmOxSg=="; Max-Age=63072000; Expires=Wed,
+ 20 Sep 2023 21:47:48 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
+ - guest_id=v1%3A163217446858292923; Max-Age=63072000; Expires=Wed, 20 Sep 2023
+ 21:47:48 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
+ strict-transport-security:
+ - max-age=631138519
+ x-access-level:
+ - read-write-directmessages
+ x-connection-hash:
+ - b749ed00177b9e8d4fa0590d2ddcb7210910a14c470247d2796add7567c67c6f
+ x-content-type-options:
+ - nosniff
+ x-frame-options:
+ - SAMEORIGIN
+ x-rate-limit-limit:
+ - '50'
+ x-rate-limit-remaining:
+ - '49'
+ x-rate-limit-reset:
+ - '1632175368'
+ 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%3A163217446858292923; personalization_id="v1_tx5lZdBKqUcj82GIzmOxSg=="
+ 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/muting/17874544
+ response:
+ body:
+ string: !!binary |
+ H4sIAAAAAAAAAKpWSkksSVSyqlbKLS3JzEtXskpLzClOra0FAAAA//8DAL40mrYZAAAA
+ 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:
+ - '51'
+ content-type:
+ - application/json; charset=utf-8
+ date:
+ - Mon, 20 Sep 2021 21:47:48 UTC
+ server:
+ - tsa_a
+ strict-transport-security:
+ - max-age=631138519
+ x-access-level:
+ - read-write-directmessages
+ x-connection-hash:
+ - b749ed00177b9e8d4fa0590d2ddcb7210910a14c470247d2796add7567c67c6f
+ x-content-type-options:
+ - nosniff
+ x-frame-options:
+ - SAMEORIGIN
+ x-rate-limit-limit:
+ - '50'
+ x-rate-limit-remaining:
+ - '49'
+ x-rate-limit-reset:
+ - '1632175368'
+ x-xss-protection:
+ - '0'
+ status:
+ code: 200
+ message: OK
+version: 1
.. automethod:: Client.follow
+Mutes
+-----
+
+.. automethod:: Client.unmute
+
+.. automethod:: Client.mute
+
User lookup
-----------
user_id = 783214 # User ID for @Twitter
self.client.get_users_following(user_id)
+ @tape.use_cassette("test_mute_and_unmute.yaml", serializer="yaml")
+ def test_mute_and_unmute(self):
+ user_id = 17874544 # User ID for @TwitterSupport
+ self.client.mute(user_id)
+ self.client.unmute(user_id)
+
@tape.use_cassette("test_get_user.yaml", serializer="yaml")
def test_get_user(self):
self.client.get_user(username="Twitter")
user_auth=True
)
+ # Mutes
+
+ def unmute(self, target_user_id):
+ """Allows an authenticated user ID to unmute the target user.
+
+ The request succeeds with no action when the user sends a request to a
+ user they're not muting or have already unmuted.
+
+ Parameters
+ ----------
+ target_user_id : Union[int, str]
+ The user ID of the user that you would like to unmute.
+
+ Returns
+ -------
+ Union[dict, requests.Response, Response]
+
+ References
+ ----------
+ https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/delete-users-user_id-muting
+ """
+ source_user_id = self.access_token.partition('-')[0]
+ route = f"/2/users/{source_user_id}/muting/{target_user_id}"
+
+ return self._make_request("DELETE", route, user_auth=True)
+
+ def mute(self, target_user_id):
+ """Allows an authenticated user ID to mute the target user.
+
+ Parameters
+ ----------
+ target_user_id : Union[int, str]
+ The user ID of the user that you would like to mute.
+
+ Returns
+ -------
+ Union[dict, requests.Response, Response]
+
+ References
+ ----------
+ https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/post-users-user_id-muting
+ """
+ id = self.access_token.partition('-')[0]
+ route = f"/2/users/{id}/muting"
+
+ return self._make_request(
+ "POST", route, json={"target_user_id": str(target_user_id)},
+ user_auth=True
+ )
+
# User lookup
def get_user(self, *, id=None, username=None, user_auth=False, **params):