twitter api on python code example
Example 1: twitter api python
$ pip install tweepy
-
import tweepy
auth = tweepy.OAuthHandler("YOU_CONSUMER_KEY", "YOUR_CONSUMER_SECRET")
auth.set_access_token("YOUR_ACCESS_TOKEN", "YOUR_ACCESS_SECRET")
api = tweepy.API(auth)
tweet = api.update_status("My first tweet!")
api.create_favorite(tweet.id)
Example 2: how to get tweets from twitter api in python
import os
import tweepy as tw
import pandas as pd
consumer_key= 'yourkeyhere'
consumer_secret= 'yourkeyhere'
access_token= 'yourkeyhere'
access_token_secret= 'yourkeyhere'
auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth, wait_on_rate_limit=True)
api.update_status("Look, I'm tweeting from #Python in my #earthanalytics class! @EarthLabCU")
search_words = "#wildfires"
date_since = "2018-11-16"
tweets = tw.Cursor(api.search,
q=search_words,
lang="en",
since=date_since).items(5)
tweets = tw.Cursor(api.search,
q=search_words,
lang="en",
since=date_since).items(5)
for tweet in tweets:
print(tweet.text)
tweets = tw.Cursor(api.search,
q=search_words,
lang="en",
since=date_since).items(5)
[tweet.text for tweet in tweets]
Example 3: twitter bot python
Check this link out:
https://realpython.com/twitter-bot-python-tweepy/
Example 4: twitter api python
pip install python-twitter