我收到的计数和细分推文

问题描述 投票:0回答:2

有没有办法计算有多少人发推特给我,并包含一个特定的标签,并按用户分类,例如,

  • 用户A使用#certainhashtag向我发送了10次推文
  • 用户B使用#certainhashtag 8次向我发送推文

等等

api twitter
2个回答
2
投票

您可以将q参数与https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html一起使用搜索API(@you #certainhashtag)。

所以在这里你有推文提到你并包含你的标签。

您可以将它们写入CSV文件。要在Linux系统上执行计数,您将使用以下几个命令来实现它:awk,cut,grep,wc,uniq ...

或者在获取推文时,您可以编写如下过滤器:

  • 如果推文的发件人用户是@you:pass(结果可以返回你的推文)
  • 管理每个用户ID的计数器。

0
投票

您可以使用counts endpoint使用高级搜索API来执行此操作。 30天和完整归档搜索API都支持计费,在付费高级层(在免费沙箱中不可用)。

您将进行类似于此查询的查询,以获取计数数据的时间序列。

{
    "query": "to:andypiper from:userA #certainhashtag",
    "bucket": "day"
}

结果看起来像这样(对于30天的搜索请求):

{
    "results": [
        {
            "timePeriod": "201809040000",
            "count": 2
        },
        {
            "timePeriod": "201809030000",
            "count": 0
        },
        {
            "timePeriod": "201809020000",
            "count": 0
        },
        {
            "timePeriod": "201809010000",
            "count": 0
        },
        {
            "timePeriod": "201808310000",
            "count": 0
        },
        {
            "timePeriod": "201808300000",
            "count": 0
        },
        {
            "timePeriod": "201808290000",
            "count": 0
        },
        {
            "timePeriod": "201808280000",
            "count": 0
        },
        {
            "timePeriod": "201808270000",
            "count": 0
        },
        {
            "timePeriod": "201808260000",
            "count": 0
        },
        {
            "timePeriod": "201808250000",
            "count": 0
        },
        {
            "timePeriod": "201808240000",
            "count": 0
        },
        {
            "timePeriod": "201808230000",
            "count": 0
        },
        {
            "timePeriod": "201808220000",
            "count": 0
        },
        {
            "timePeriod": "201808210000",
            "count": 0
        },
        {
            "timePeriod": "201808200000",
            "count": 0
        },
        {
            "timePeriod": "201808190000",
            "count": 0
        },
        {
            "timePeriod": "201808180000",
            "count": 0
        },
        {
            "timePeriod": "201808170000",
            "count": 0
        },
        {
            "timePeriod": "201808160000",
            "count": 0
        },
        {
            "timePeriod": "201808150000",
            "count": 0
        },
        {
            "timePeriod": "201808140000",
            "count": 0
        },
        {
            "timePeriod": "201808130000",
            "count": 0
        },
        {
            "timePeriod": "201808120000",
            "count": 0
        },
        {
            "timePeriod": "201808110000",
            "count": 0
        },
        {
            "timePeriod": "201808100000",
            "count": 0
        },
        {
            "timePeriod": "201808090000",
            "count": 0
        },
        {
            "timePeriod": "201808080000",
            "count": 0
        },
        {
            "timePeriod": "201808070000",
            "count": 0
        },
        {
            "timePeriod": "201808060000",
            "count": 0
        },
        {
            "timePeriod": "201808050000",
            "count": 0
        }
    ],
    "totalCount": 2,
    "requestParameters": {
        "bucket": "day",
        "fromDate": "201808050000",
        "toDate": "201809041241"
    }
}

然后你只需要计算总数。

© www.soinside.com 2019 - 2024. All rights reserved.