Skip to content

Commit

Permalink
Authenticate twitter api
Browse files Browse the repository at this point in the history
  • Loading branch information
Intina47 committed Apr 17, 2024
1 parent a43cb96 commit c592d81
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions twitter_bot/twitter_api.py
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()

0 comments on commit c592d81

Please sign in to comment.