File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ import tweepy
2
+
3
+ def get_twitter_api ():
4
+ consumer_key = '' # API key
5
+ consumer_secret = '' # API secret key
6
+ access_token = ''
7
+ access_token_secret = ''
8
+
9
+ # Correcting the class name for the OAuth handler
10
+ auth = tweepy .OAuthHandler (consumer_key , consumer_secret )
11
+ auth .set_access_token (access_token , access_token_secret )
12
+
13
+ api = tweepy .API (auth )
14
+
15
+ # Attempt to use the API to confirm authentication works
16
+ try :
17
+ api .verify_credentials ()
18
+ print ("Successfully authenticated with Twitter API." )
19
+ except tweepy .TweepyException as e :
20
+ print (f"Failed to authenticate with Twitter API: { e } " )
21
+ return None # Optionally return None or handle differently if auth fails
22
+
23
+ return api
24
+
25
+ # Call the function to test authentication
26
+ api = get_twitter_api ()
You can’t perform that action at this time.
0 commit comments