Masum Billah
Masum Billah

Reputation: 135

Extracting data / Tweets based on a specific Hashtag

I want to extract data / Tweets based on a specific Hashtag. My python codes are working fine with any hashtag, except "#LetsTaxThis". Mainly This is the hashtag I want to use to extract data from tweeter.

Once I run my code using this hashtag I can see only 2 tweets, But there is already 1000+ tweets with this hashtag.

My CONSUMER_KEY , CONSUMER_SECRET , ACCESS_TOKEN and ACCESS_SECRET are fine. Because other hashtags are working.

import tweepy           # To consume Twitter's API
import pandas as pd     # To handle data
import numpy as np      # For number computing

# For plotting and visualization:
from IPython.display import display
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline



# Twitter App access keys for @user

# Consume:
CONSUMER_KEY    = '--------'
CONSUMER_SECRET = '----------------'

# Access:
ACCESS_TOKEN  = '--------------'
ACCESS_SECRET = '-------------'

#------------------
# We import our access keys:
from credentials import *    # This will allow us to use the keys as variables

# API's setup:
def twitter_setup():
    """
    Utility function to setup the Twitter's API
    with our access keys provided.
    """
    # Authentication and access using keys:
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

    # Return API with authentication:
    api = tweepy.API(auth)
    return api

    ------------------

    # We create an extractor object:
extractor = twitter_setup()

# We create a tweet list as follows:
#tweets = extractor.user_timeline(screen_name="@iamsrk", count=600)
tweets = extractor.search(q="#letsTaxThis", count=200)

print("Number of tweets extracted: {}.\n".format(len(tweets)))

# We print the most recent 5 tweets:
#print("3 recent tweets:\n")
for tweet in tweets[:3]:
    print(tweet.text)
    print()

    -----------------------

I look forward to hearing from you :) .

Thanks In Advance :)

Upvotes: 3

Views: 1562

Answers (1)

Jonas
Jonas

Reputation: 4048

The Search API returns tweets going back one week only. You would need to get approval to use the Premium Search API to get older tweets.

Upvotes: 2

Related Questions