微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用python查找任何用户在twitter中关注的主题?

如何解决如何使用python查找任何用户在twitter中关注的主题?

我只是想构建一个网络应用程序并尝试找到任何用户关注的主题。我试图获取时间线并运行 topic-model(classifier) 但这确实需要时间。有什么办法可以从 tweepy's get_user 函数中找到它?谢谢

解决方法

我可能会研究 Twitter API 我开发了一个 Telegram bot,作为谷歌网络应用程序托管,用于连接 Twitter,API 非常丰富 祝你好运

,

没有直接的方法可以通过 Twitter API 找到用户关注的主题,但在 Twitter API v2 中,您可以找到与用户发布的推文相关联的主题。 >

(请注意,在发布此答案时,Tweepy 尚不支持 API v2,但他们正在致力于此 - TwitterDev GitHub 中有一些 Python 示例,它们在可能的情况下使用标准 Python 库做工作)

这里的一般步骤是:

  • 拥有一个已获批准的 Twitter 开发者帐户,并创建一个新项目和应用以访问 v2 API
  • 为您感兴趣的用户 ID 调用 user Tweet timeline endpoint,将 context_annotations Tweet 字段添加到您的请求中,以便每条推文都附有主题信息。

这将以类似这样的格式返回数据(以@TwitterDev 帐户为例):

{
    "data": [
        {
            "context_annotations": [
                {
                    "domain": {
                        "description": "Top level interests and hobbies groupings,like Food or Travel","id": "65","name": "Interests and Hobbies Vertical"
                    },"entity": {
                        "description": "Technology and computing","id": "848920371311001600","name": "Technology"
                    }
                },{
                    "domain": {
                        "description": "A grouping of interests and hobbies entities,like Novelty Food or Destinations","id": "66","name": "Interests and Hobbies Category"
                    },"entity": {
                        "description": "Computer programming","id": "848921413196984320","name": "Computer programming"
                    }
                }
            ],"created_at": "2021-01-05T22:45:35.000Z","id": "1346588685555306497","text": "\ud83d\udd11\ud83d\udd11 On Tuesday,January 12th,we\u2019re removing the ability to view existing consumer API keys from the developer portal. Be sure to save your API keys in a secure place before Tuesday to ensure your access to the #TwitterAPI is not disrupted. Learn more https://twittercommunity.com/t/ability-to-view-existing-consumer-api-keys-being-removed-from-your-developer-dashboard/147849"
        }
...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。