根据特定的标签提取数据/推文

时间:2018-08-07 02:31:23

标签: python-3.x twitter data-science

我想基于特定的标签提取数据/推文。我的python代码可以很好地与任何主题标签一起使用,“#LetsTaxThis”除外。主要是我想用来从高音扬声器提取数据的主题标签。

使用此井号标签运行代码后,我只能看到2条推文,但是已经有1000条以上的井号标签。

我的CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN和ACCESS_SECRET都可以。因为其他标签仍在工作。

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()

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

我希望收到您的来信:)。

先谢谢了:)

1 个答案:

答案 0 :(得分:2)

Search API仅返回一周前的推文。您需要获得批准才能使用Premium Search API来获取较旧的推文。