-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import tweepy | ||
|
||
def get_twitter_api(): | ||
consumer_key = '' # API key | ||
consumer_secret = '' # API secret key | ||
access_token = '' | ||
access_token_secret = '' | ||
|
||
# Correcting the class name for the OAuth handler | ||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | ||
auth.set_access_token(access_token, access_token_secret) | ||
|
||
api = tweepy.API(auth) | ||
|
||
# Attempt to use the API to confirm authentication works | ||
try: | ||
api.verify_credentials() | ||
print("Successfully authenticated with Twitter API.") | ||
except tweepy.TweepyException as e: | ||
print(f"Failed to authenticate with Twitter API: {e}") | ||
return None # Optionally return None or handle differently if auth fails | ||
|
||
return api | ||
|
||
# Call the function to test authentication | ||
api = get_twitter_api() |