Skip to main content

**Not once was `backoff`, `error_id`, or `error_name` returned by the API.**

Not once was backoff, error_id, or error_name returned by the API.

Complete Code to Replicate:

##Complete Code to Replicate:

const sortOrder   = "desc";  // "asc" or "desc"
const cYourKey    = "&key=U4DMV*8nvpm3EOpvf69Rxw(("; // best to use your own
const cMaxPages   = 300;
const tagStats    = {};
let PageNm      = 1;
let timeDiffSum = 0;
let timeDiffCnt = 0;
let lastTime    = null;

getPageOfTags (PageNm);
function sessionStat () {
    console.log (`Fetched ${PageNm} pages from the API.`);
    console.log (`Found ${Object.keys(tagStats).length} tag names.`);
    console.log (`Average API rate was ${ (1000.0 * timeDiffCnt / timeDiffSum).toFixed(2) } calls per second.`);
}
function getPageOfTags (pageNum) {
    fetch (
        `https://api.stackexchange.com/2.2/tags?page=${pageNum}&pagesize=100&sort=name&order=${sortOrder}&site=stackoverflow${cYourKey}`
    )
    .then (function (response) {
        if (response.ok)  return response.json();
        throw new Error (`API problem: Error ${response.status}, ${response.statusText}`);
    } )
    .then (function (rJsn) {
        if (rJsn.backoff  ||  rJsn.error_id) {
            throw new Error (`From API: Backoff ${rJsn.backoff}, Error: ${rJsn.error_id}, ${rJsn.error_message}, ${rJsn.error_name}`);
        }
        let timenow = (new Date() ).getTime();
        if (lastTime) {
            let timediff    = timenow - lastTime;
            timeDiffCnt++;
            timeDiffSum    += timediff;
        }
        lastTime    = timenow;
        console.log (`Page:${ (''+PageNm).padStart(4)}, Quota remaining: ${rJsn.quota_remaining}; Items found: ${rJsn.items.length}`, timenow);

        let allDone = ! rJsn.has_more;
        let zTags   = rJsn.items;
        for (let zTag of zTags) {
            tagStats[zTag.name]  = zTag.count;
        }
        if (rJsn.has_more) {
            if (PageNm >= cMaxPages)
                allDone = true;
            else {
                PageNm++;
                getPageOfTags (PageNm);
            }
        }
        if (allDone) {
            //--- Do final processing here...
            console.log ("All done. Running sessionStat()...");
            sessionStat ();
        }
    } )
    .catch (function (error) {
        console.log (`Page:${ ('' + PageNm).padStart(4)}, ERROR:`);
        console.error (error);
    } );
};
var sortOrder   = "desc";  // "asc" or "desc"
var cYourKey    = "";  // "&key=Best to Get and Use your own key";
var cMaxPages   = 300;
var tagStats    = {};
var PageNm      = 1;
var timeDiffSum = 0;
var timeDiffCnt = 0;
var lastTime    = null;

getPageOfTags (PageNm);
function sessionStat () {
    console.log (`Fetched ${PageNm} pages from the API.`);
    console.log (`Found ${Object.keys(tagStats).length} tag names.`);
    console.log (`Average API rate was ${ (1000.0 * timeDiffCnt / timeDiffSum).toFixed(2) } calls per second.`);
}
function getPageOfTags (pageNum) {
    fetch (
        `https://api.stackexchange.com/2.2/tags?page=${pageNum}&pagesize=100&sort=name&order=${sortOrder}&site=stackoverflow${cYourKey}`
    )
    .then (function (response) {
        if (response.ok)  return response.json();
        throw new Error (`API problem: Error ${response.status}, ${response.statusText}`);
    } )
    .then (function (rJsn) {
        if (rJsn.backoff  ||  rJsn.error_id) {
            throw new Error (`From API: Backoff ${rJsn.backoff}, Error: ${rJsn.error_id}, ${rJsn.error_message}, ${rJsn.error_name}`);
        }
        let timenow = (new Date() ).getTime();
        if (lastTime) {
            let timediff    = timenow - lastTime;
            timeDiffCnt++;
            timeDiffSum    += timediff;
        }
        lastTime    = timenow;
        console.log (`Page:${ (''+PageNm).padStart(4)}, Quota remaining: ${rJsn.quota_remaining}; Items found: ${rJsn.items.length}`, timenow);

        let allDone = ! rJsn.has_more;
        let zTags   = rJsn.items;
        for (let zTag of zTags) {
            tagStats[zTag.name]  = zTag.count;
        }
        if (rJsn.has_more) {
            if (PageNm >= cMaxPages)
                allDone = true;
            else {
                PageNm++;
                getPageOfTags (PageNm);
            }
        }
        if (allDone) {
            //--- Do final processing here...
            console.log ("All done. Running sessionStat()...");
            sessionStat ();
        }
    } );
};
 


**Not once was `backoff`, `error_id`, or `error_name` returned by the API.**

##Complete Code to Replicate:

var sortOrder   = "desc";  // "asc" or "desc"
var cYourKey    = "";  // "&key=Best to Get and Use your own key";
var cMaxPages   = 300;
var tagStats    = {};
var PageNm      = 1;
var timeDiffSum = 0;
var timeDiffCnt = 0;
var lastTime    = null;

getPageOfTags (PageNm);
function sessionStat () {
    console.log (`Fetched ${PageNm} pages from the API.`);
    console.log (`Found ${Object.keys(tagStats).length} tag names.`);
    console.log (`Average API rate was ${ (1000.0 * timeDiffCnt / timeDiffSum).toFixed(2) } calls per second.`);
}
function getPageOfTags (pageNum) {
    fetch (
        `https://api.stackexchange.com/2.2/tags?page=${pageNum}&pagesize=100&sort=name&order=${sortOrder}&site=stackoverflow${cYourKey}`
    )
    .then (function (response) {
        if (response.ok)  return response.json();
        throw new Error (`API problem: Error ${response.status}, ${response.statusText}`);
    } )
    .then (function (rJsn) {
        if (rJsn.backoff  ||  rJsn.error_id) {
            throw new Error (`From API: Backoff ${rJsn.backoff}, Error: ${rJsn.error_id}, ${rJsn.error_message}, ${rJsn.error_name}`);
        }
        let timenow = (new Date() ).getTime();
        if (lastTime) {
            let timediff    = timenow - lastTime;
            timeDiffCnt++;
            timeDiffSum    += timediff;
        }
        lastTime    = timenow;
        console.log (`Page:${ (''+PageNm).padStart(4)}, Quota remaining: ${rJsn.quota_remaining}; Items found: ${rJsn.items.length}`, timenow);

        let allDone = ! rJsn.has_more;
        let zTags   = rJsn.items;
        for (let zTag of zTags) {
            tagStats[zTag.name]  = zTag.count;
        }
        if (rJsn.has_more) {
            if (PageNm >= cMaxPages)
                allDone = true;
            else {
                PageNm++;
                getPageOfTags (PageNm);
            }
        }
        if (allDone) {
            //--- Do final processing here...
            console.log ("All done. Running sessionStat()...");
            sessionStat ();
        }
    } );
};

Not once was backoff, error_id, or error_name returned by the API.

Complete Code to Replicate:

const sortOrder   = "desc";  // "asc" or "desc"
const cYourKey    = "&key=U4DMV*8nvpm3EOpvf69Rxw(("; // best to use your own
const cMaxPages   = 300;
const tagStats    = {};
let PageNm      = 1;
let timeDiffSum = 0;
let timeDiffCnt = 0;
let lastTime    = null;

getPageOfTags (PageNm);
function sessionStat () {
    console.log (`Fetched ${PageNm} pages from the API.`);
    console.log (`Found ${Object.keys(tagStats).length} tag names.`);
    console.log (`Average API rate was ${ (1000.0 * timeDiffCnt / timeDiffSum).toFixed(2) } calls per second.`);
}
function getPageOfTags (pageNum) {
    fetch (
        `https://api.stackexchange.com/2.2/tags?page=${pageNum}&pagesize=100&sort=name&order=${sortOrder}&site=stackoverflow${cYourKey}`
    )
    .then (function (response) {
        if (response.ok)  return response.json();
        throw new Error (`API problem: Error ${response.status}, ${response.statusText}`);
    } )
    .then (function (rJsn) {
        if (rJsn.backoff  ||  rJsn.error_id) {
            throw new Error (`From API: Backoff ${rJsn.backoff}, Error: ${rJsn.error_id}, ${rJsn.error_message}, ${rJsn.error_name}`);
        }
        let timenow = (new Date() ).getTime();
        if (lastTime) {
            let timediff    = timenow - lastTime;
            timeDiffCnt++;
            timeDiffSum    += timediff;
        }
        lastTime    = timenow;
        console.log (`Page:${ (''+PageNm).padStart(4)}, Quota remaining: ${rJsn.quota_remaining}; Items found: ${rJsn.items.length}`, timenow);

        let allDone = ! rJsn.has_more;
        let zTags   = rJsn.items;
        for (let zTag of zTags) {
            tagStats[zTag.name]  = zTag.count;
        }
        if (rJsn.has_more) {
            if (PageNm >= cMaxPages)
                allDone = true;
            else {
                PageNm++;
                getPageOfTags (PageNm);
            }
        }
        if (allDone) {
            //--- Do final processing here...
            console.log ("All done. Running sessionStat()...");
            sessionStat ();
        }
    } )
    .catch (function (error) {
        console.log (`Page:${ ('' + PageNm).padStart(4)}, ERROR:`);
        console.error (error);
    } );
};
 

deleted 290 characters in body
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64
added 137 characters in body
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

It is not a particular tag that does it as fetching tags by name (ascending) fails at page 181 the same as fetching tags by name (descending).
(Note that there are currently 553 pages of tags, so fetching 181 pages desc gives all different values than fetching 181 pages asc.)

It is not a particular tag that does it as fetching tags by name (ascending) fails at page 181 the same as fetching tags by name (descending).

It is not a particular tag that does it as fetching tags by name (ascending) fails at page 181 the same as fetching tags by name (descending).
(Note that there are currently 553 pages of tags, so fetching 181 pages desc gives all different values than fetching 181 pages asc.)

Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64
Loading