Home > OS >  Need StackExchange API for question count for particular tag
Need StackExchange API for question count for particular tag

Time:11-05

I tried Questions Dos from stackexchange to get total count of questions for perticular tag but it has some limitation like That API return only 30 data at a time and max 100 data(question) But I need more than 10,000 counts, If I go through all page and count those questions using js or php it will take lots of time any sort way to get the total count of that question?

Example API: https://api.stackexchange.com/2.3/questions?tagged=airflow&site=stackoverflow;

I tried https://api.stackexchange.com/2.3/questions?tagged=airflow&site=stackoverflow API

and I get the first 30 items

But I want total number of those questions Screenshot

CodePudding user response:

To get a total of tagged "airflow" you need to use a custom filter

https://api.stackexchange.com/2.3/questions?tagged=airflow&site=stackoverflow&filter=!w-*Ytm8YGWVl9..xoC

{ "total": 11509,
 ...
}

Alternative is looking at tags - I am not sure why there is a difference in the airflow tags - I have raised a META question if "synonyms" makes the difference

One tag:

https://api.stackexchange.com/2.3/tags/airflow/info?site=stackoverflow

{
  "items": [
  {
    "has_synonyms": true,
    "count": 10263,
    "name": "airflow"

Tags with airflow in the name

https://api.stackexchange.com/2.3/tags?order=desc&sort=popular&inname=airflow&site=stackoverflow

document.getElementById('report').innerHTML =  resultAsOf20231104.items
  .map(({name,count}) => `${name}: ${count}`).join('<br/>')
<div id="report"></div>


<script>
const resultAsOf20231104 = { "items": [ { "has_synonyms": true, "is_moderator_only": false, "is_required": false, "count": 10263, "name": "airflow" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 1253, "name": "airflow-scheduler" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 710, "name": "airflow-2.x" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 170, "name": "airflow-webserver" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 80, "name": "airflow-api" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 76, "name": "airflow-taskflow" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 27, "name": "airflow-xcom" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 11, "name": "airflow-connections" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 5, "name": "airflow-celery" }, { "has_synonyms": false, "is_moderator_only": false, "is_required": false, "count": 4, "name": "airflow-k8s" } ], "has_more": false, "quota_max": 300, "quota_remaining": 294 }
</script>

If you need to run over more than 100 to count, then you need to throttle your requests and add paging to your code.

It is not trivial but I have done so for Github.

  • Related