【问题标题】:twitter api retweet excludetwitter api 转推 排除
【发布时间】:2019-04-12 05:06:46
【问题描述】:

所以我目前正在尝试从 Twitter 帐户中挖掘推文,但我想排除转推,以便我可以为我的项目获取 200 条推文数据。目前我有一个工作代码来挖掘数据馈送,但仍然包含 Re-Tweets。我已经确定要排除您需要添加的 Re-Tweets -RT 在代码中,但我根本不知道在哪里,因为我对编程很陌生。

(目前使用 Python 的 Twitter API (Tweepy) 和使用 Spyder 的 Python 3.6。)

import tweepy
from tweepy import OAuthHandler
import pandas as pd

consumer_key = 'consumer_key'
consumer_secret = 'consumer_secret'
access_token = 'access_token'
access_secret = 'access_secret'

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

api = tweepy.API(auth)

api = tweepy.API(auth)
screen_name='screen_name'
tweets = api.user_timeline(screen_name, count=200)
save=['']*len(tweets)

for i in range(len(tweets)):
save[i]=tweets[i].text
print(tweets[i].text)

data = pd.DataFrame(save)
data.to_csv("results.csv")

任何人都可以帮助我,最好是完整的代码部分以删除转推。非常感谢

【问题讨论】:

标签: python twitter


【解决方案1】:

当我使用 tweepy 从 twitter 检索推文时遇到了同样的问题,对我有用的是我使用了带有内置请求的 twitter api,即 http 请求。 要排除转发,您可以在查询参数中传递 -RT 运算符。

api 的文档。

【讨论】:

  • 在问题中它说“[...] 你需要在代码中输入-RT 但我根本不知道在哪里 [..]”,所以你的回答说使用“ -RT" 并没有真正的帮助。
【解决方案2】:

在您的代码中更改这一行:

tweets = api.user_timeline(screen_name, count=200)

到以下:

tweets = api.user_timeline(screen_name, count=200, include_rts=False)

此 Twitter 文档可能会有所帮助:https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html

【讨论】:

    猜你喜欢
    • 2016-11-07
    • 2020-10-12
    • 2014-03-12
    • 2019-05-12
    • 1970-01-01
    • 2016-06-26
    • 2011-10-20
    • 2011-05-05
    • 2011-06-21
    相关资源
    最近更新 更多