Update usage of OAuthHandler to OAuth1UserHandler
authorHarmon <Harmon758@gmail.com>
Wed, 9 Feb 2022 21:51:52 +0000 (15:51 -0600)
committerHarmon <Harmon758@gmail.com>
Wed, 9 Feb 2022 21:51:52 +0000 (15:51 -0600)
docs/getting_started.rst
examples/API_v1/authentication.py
examples/API_v1/follow_followers.py
examples/API_v1/pin-based_authorization.py
examples/API_v1/rate_limit_handling.py
examples/API_v1/update_status.py
tests/config.py
tests/test_auth.py
tweepy/client.py

index 39e26e82d4e31d208bad7de54b9d0a9cdd1cda3f..449e444f0a9f51ae83a0d423ad028759fd9a3ad1 100644 (file)
@@ -19,8 +19,9 @@ Hello Tweepy
 
    import tweepy
 
-   auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
-   auth.set_access_token(access_token, access_token_secret)
+   auth = tweepy.OAuth1UserHandler(
+      consumer_key, consumer_secret, access_token, access_token_secret
+   )
 
    api = tweepy.API(auth)
    
index c737d5b69616d29d890eb77fb1b19fdf2e7e816f..b436aa1be35379ab6eb1d4c1c1e8a6a1edeb4084 100644 (file)
@@ -15,8 +15,9 @@ consumer_secret = ""
 access_token = ""
 access_token_secret = ""
 
-auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
-auth.set_access_token(access_token, access_token_secret)
+auth = tweepy.OAuth1UserHandler(
+    consumer_key, consumer_secret, access_token, access_token_secret
+)
 
 api = tweepy.API(auth)
 
index 0c49a34020d070cb8d8ee059862ddf944f6db173..00095ee5a7d2a6597e4d81b438b51d21ab619b04 100644 (file)
@@ -6,8 +6,9 @@ consumer_secret = ""
 access_token = ""
 access_token_secret = ""
 
-auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
-auth.set_access_token(access_token, access_token_secret)
+auth = tweepy.OAuth1UserHandler(
+    consumer_key, consumer_secret, access_token, access_token_secret
+)
 
 api = tweepy.API(auth)
 
index 9c3eea6c4707d9bd81a4f6176e5d6ce02c0143ba..471aa881a99c94b250b9b319d678a5c0bc08966e 100644 (file)
@@ -10,7 +10,7 @@ import tweepy
 consumer_key = ""
 consumer_secret = ""
 
-auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
+auth = tweepy.OAuth1UserHandler(consumer_key, consumer_secret)
 
 # This prints a URL that can be used to authorize your app
 # After granting access to the app, a PIN to complete the authorization process
index 3845a5873ca46445baecb59b2056a840b5547a44..cea1807bcb0a54147b4e03311f7a079466025395 100644 (file)
@@ -6,8 +6,9 @@ consumer_secret = ""
 access_token = ""
 access_token_secret = ""
 
-auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
-auth.set_access_token(access_token, access_token_secret)
+auth = tweepy.OAuth1UserHandler(
+    consumer_key, consumer_secret, access_token, access_token_secret
+)
 
 # Setting wait_on_rate_limit to True when initializing API will initialize an
 # instance, called api here, that will automatically wait, using time.sleep,
index 7c1fa69543348f421b6ee5e26acec4bba2d77784..aad24ede03c7be566a95f21245a39a6d44ad7e3a 100644 (file)
@@ -6,8 +6,9 @@ consumer_secret = ""
 access_token = ""
 access_token_secret = ""
 
-auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
-auth.set_access_token(access_token, access_token_secret)
+auth = tweepy.OAuth1UserHandler(
+    consumer_key, consumer_secret, access_token, access_token_secret
+)
 
 api = tweepy.API(auth)
 
index 6f65c4072bc2db81ea9a7417dcd9a48adfbc770b..db6abf0d5eb41ae9e7d91d292685cb5af10e28a6 100644 (file)
@@ -4,7 +4,7 @@ import unittest
 import vcr
 
 from tweepy.api import API
-from tweepy.auth import OAuthHandler
+from tweepy.auth import OAuth1UserHandler
 
 
 user_id = os.environ.get('TWITTER_USER_ID', '1072250532645998596')
@@ -35,6 +35,7 @@ class TweepyTestCase(unittest.TestCase):
 
 
 def create_auth():
-    auth = OAuthHandler(consumer_key, consumer_secret)
-    auth.set_access_token(access_token, access_token_secret)
+    auth = OAuth1UserHandler(
+        consumer_key, consumer_secret, access_token, access_token_secret
+    )
     return auth
index 29ea4abbf7a04f7850e18dad785a752c728a4306..015d05c28abd89e7534557db245703a7594bddf3 100644 (file)
@@ -2,7 +2,7 @@ import random
 import unittest
 
 from config import *
-from tweepy import API, OAuthHandler
+from tweepy import API, OAuth1UserHandler
 
 
 class TweepyAuthTests(unittest.TestCase):
@@ -11,7 +11,7 @@ class TweepyAuthTests(unittest.TestCase):
         if not consumer_key or not consumer_secret:
             self.skipTest("Missing consumer key and/or secret")
 
-        auth = OAuthHandler(consumer_key, consumer_secret)
+        auth = OAuth1UserHandler(consumer_key, consumer_secret)
 
         # test getting access token
         auth_url = auth.get_authorization_url()
@@ -30,7 +30,7 @@ class TweepyAuthTests(unittest.TestCase):
         if not consumer_key or not consumer_secret:
             self.skipTest("Missing consumer key and/or secret")
 
-        auth = OAuthHandler(consumer_key, consumer_secret)
+        auth = OAuth1UserHandler(consumer_key, consumer_secret)
         auth_url = auth.get_authorization_url(access_type='read')
         print('Please open: ' + auth_url)
         answer = input('Did Twitter only request read permissions? (y/n) ')
index 8848afbac4d1b0868fc46e8886ae3f0629939c5f..4a20e1df10f638df6e2e14d6af2c266825262b62 100644 (file)
@@ -12,7 +12,7 @@ import warnings
 import requests
 
 import tweepy
-from tweepy.auth import OAuthHandler
+from tweepy.auth import OAuth1UserHandler
 from tweepy.errors import (
     BadRequest, Forbidden, HTTPException, TooManyRequests, TwitterServerError,
     Unauthorized
@@ -92,8 +92,10 @@ class Client:
         headers = {"User-Agent": self.user_agent}
         auth = None
         if user_auth:
-            auth = OAuthHandler(self.consumer_key, self.consumer_secret)
-            auth.set_access_token(self.access_token, self.access_token_secret)
+            auth = OAuth1UserHandler(
+                self.consumer_key, self.consumer_secret,
+                self.access_token, self.access_token_secret
+            )
             auth = auth.apply_auth()
         else:
             headers["Authorization"] = f"Bearer {self.bearer_token}"