【问题标题】:How to retrieve a user's tweets without retweets and replies in R?如何在 R 中没有转发和回复的情况下检索用户的推文?
【发布时间】:2020-09-11 10:08:56
【问题描述】:

我想检索用户的推文以进行文本分析。我已经从 twitteR 包 中尝试过 userTimeline,但它只检索到 3200 条推文,包括回复和转发。是否有其他选项可用于仅下载使用 R 的用户的推文?

提前致谢!

【问题讨论】:

  • 欢迎堆栈溢出。它是一个用于编程和代码问题的网站,而不是推荐软件或软件包。说了这么多,有没有看过相关的 cran task view 进行文本分析:cran.r-project.org/web/views?
  • 嘿,彼得,感谢您的推荐。我检查了“Twitter”、“文本分析”,但没有找到任何相关内容。

标签: r twitter nlp twitter-oauth


【解决方案1】:

我以前从未在 R 中编写过代码,但我对 Twitter API 有一些经验,并且使用 python 在 Tweepy 库中做过类似的事情。

状态对象有几个属性,你可以阅读关于here;

您可以通过检查推文对象是否具有 retweeted_status 属性来检查推文是否为转推。

您可以通过检查 in_reply_to_status_id 属性来检查推文是否是对另一条推文的回复。如果推文是回复,则此属性返回正在回复的推文的 ID,如果不是,则返回 None。

在python中,实现这个的代码是;

get_tweets = api.user_timeline(username)
for tweets in get_tweets:
    if hasattr(tweets, 'retweeted_status') or tweets.in_reply_to_status_id != None:
        #Do stuff if the tweet is a retweet or reply
    else:
        #Do some other stuff if the tweet is not a retweet or reply

尝试将其转换为 R 等效项。

【讨论】:

    猜你喜欢
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 2011-07-21
    • 2019-06-13
    相关资源
    最近更新 更多