Aug 6, 2024
Obtain a Twitter Token:
Create an App:
Application Approval:
Get API Keys and Tokens:
Import Tweepy Library:
import tweepy
pip install tweepy
Store API Credentials:
api_key = 'your_api_key'
api_secret_key = 'your_api_secret_key'
access_token = 'your_access_token'
access_token_secret = 'your_access_token_secret'
Authenticate with Twitter API:
auth = tweepy.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
userResults = api.user_timeline(id='username', count=10)
for tweet in userResults:
print(tweet.text)
hasilSearch = api.search(q='jakarta', lang='id', count=10)
for tweet in hasilSearch:
print(f'{tweet.user.screen_name} tweeted: {tweet.text}')