【问题标题】:Extracting data / Tweets based on a specific Hashtag基于特定标签提取数据/推文
【发布时间】:2019-01-14 00:36:22
【问题描述】:

我想根据特定的 Hashtag 提取数据/推文。除了“#LetsTaxThis”之外,我的 python 代码适用于任何主题标签。主要是我想用来从推特中提取数据的主题标签。

使用此标签运行代码后,我只能看到 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()

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

期待您的回音:)。

提前致谢:)

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 为乔纳斯的回答干杯。如何获得批准使用高级搜索 API 来获取较旧的推文? .提前致谢:)
    • 会的,乔纳斯干杯
    猜你喜欢
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2014-06-26
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多