简体   繁体   English

twitter api转推排除

[英]twitter api retweet exclude

So i currently trying to mine tweets from Twitter account(s), but i wanted to exclude the retweets so i can get 200 of Tweets only data for my project. 所以我目前正在尝试从Twitter帐户中挖掘推文,但我想排除这些推文,以便我可以为我的项目获取200条仅Tweets数据。 Currently I have a working code to mine the data feed, but still have Re-Tweets included. 目前,我有一个可以正常工作的代码来挖掘数据提要,但是仍然包含Re-Tweets。 I have founded that to exclude Re-Tweets you need to put -RT in the code but i simply do not know where since i am pretty new to programming. 我已经发现要排除-RT ,您需要在代码中加上-RT ,但是我根本不知道在哪里,因为我是编程新手。

(Currently using Twitter API for Python (Tweepy) with Python 3.6 using Spyder.) (当前使用Twitter API for Python(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")

Can anyone help me, preferrably with complete section for the code to remove the Retweets. 任何人都可以帮助我,最好提供完整的代码部分以删除Retweets。 Thank you very much 非常感谢你

Faced the same issue back when i was using tweepy to retrieve tweets from twitter, what worked for me was that i used the twitter's api with inbuilt request ie http requests. 当我使用tweepy从Twitter检索推文时,面临同样的问题,对我有用的是,我将Twitter的api与内置请求(即http请求)一起使用。 To exclude retweets you could pass -RT operator in query parameter . 要排除转发,可以在查询参数中传递-RT运算符。

Documentation to this api . api的文档。

Change this line in your code: 在代码中更改此行:

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

to the following: 到以下内容:

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

This Twitter doc may be helpful: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html 该Twitter文档可能会有所帮助: https : //developer.twitter.com/zh-CN/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM