Add user_auth parameters to Client.unlike and Client.like
authorHarmon <Harmon758@gmail.com>
Fri, 7 Jan 2022 08:55:09 +0000 (02:55 -0600)
committerHarmon <Harmon758@gmail.com>
Fri, 7 Jan 2022 08:55:09 +0000 (02:55 -0600)
Add user_auth parameters to Client.unlike and Client.like to support OAuth 2.0 Authorization Code Flow with PKCE
https://twittercommunity.com/t/manage-likes-incorrectly-mapped-to-oauth-2-0-app-access-token-in-twitter-api-v2-authentication-mapping-documentation/164600

tweepy/client.py

index 995d28b1d66fee7a8e0d50a73708fe0bcd0f4ef3..35125a9617f3e957c4835dc2bf08204d9225d787 100644 (file)
@@ -248,7 +248,7 @@ class Client:
 
     # Likes
 
-    def unlike(self, tweet_id):
+    def unlike(self, tweet_id, *, user_auth=True):
         """Unlike a Tweet.
 
         The request succeeds with no action when the user sends a request to a
@@ -271,7 +271,7 @@ class Client:
         route = f"/2/users/{id}/likes/{tweet_id}"
 
         return self._make_request(
-            "DELETE", route, user_auth=True
+            "DELETE", route, user_auth=user_auth
         )
 
     def get_liking_users(self, id, *, user_auth=False, **params):
@@ -370,7 +370,7 @@ class Client:
             ), data_type=Tweet, user_auth=user_auth
         )
 
-    def like(self, tweet_id):
+    def like(self, tweet_id, *, user_auth=True):
         """Like a Tweet.
 
         Parameters
@@ -390,7 +390,8 @@ class Client:
         route = f"/2/users/{id}/likes"
 
         return self._make_request(
-            "POST", route, json={"tweet_id": str(tweet_id)}, user_auth=True
+            "POST", route, json={"tweet_id": str(tweet_id)},
+            user_auth=user_auth
         )
 
     # Manage Tweets