首先在这里使用堆栈交换的用户api ,您可以通过端点 url 以 JSON 格式获取堆栈溢出帐户信息。您所要做的就是在 id 字段中指定您的堆栈溢出用户 id,然后单击运行以生成端点路径。您可以通过单击您的个人资料图片来获得您的堆栈溢出用户 ID,然后它将出现在搜索栏中。

将生成的路径附加到https://api.stackexchange.com以形成端点 url。
我的堆栈交换端点网址:https ://api.stackexchange.com/2.2/users/9133459?order=desc&sort=reputation&site=stackoverflow
现在我们有了 JSON 格式的堆栈溢出信息,我们可以继续解析它并创建一个满足屏蔽要求的新端点。为此,您必须使用RunKit创建一个帐户。在 RunKit 上发布这段代码,并确保节点版本为 v4.9.1(将代码中的 url 替换为您自己之前生成的端点 url):
// variables
var endpoint = require("@runkit/runkit/json-endpoint/1.0.0");
var fetch = require("node-fetch");
var url = "https://api.stackexchange.com/2.2/users/9133459?order=desc&sort=reputation&site=stackoverflow";
let settings = { method: "Get" };
// main function
endpoint(module.exports, async function()
{
try {
await fetch(url, settings)
.then(res => res.json())
.then((json) => {
reputation = json["items"][0].reputation;
if (reputation >= 1000) {
reputation = reputation / 1000;
reputation = Math.floor(reputation * 10) / 10;
// if first decimal place is 0
if ((reputation * 10) % 10 == 0) {
// round to int
reputation = Math.round(reputation);
}
reputation = reputation.toString();
reputation += "K";
}
});
} catch(e) {
return {
"schemaVersion": 1,
"label": "STACKOVERFLOW REPUTATION",
"message": "API ERROR",
"color": "FF0000",
"labelColor": "black",
"style": "for-the-badge"
}
}
return {
"schemaVersion": 1,
"label": "STACKOVERFLOW REPUTATION",
"message": reputation,
"color": "FE7A16",
"labelColor": "black",
"style": "for-the-badge"
}
})
发布后,单击 RunKit 页面顶部的端点超链接以查看要传递给 shields 以创建徽章的端点 url。
这是我的 runkit 端点网址:https ://stack-overflow-reputation-ciqil1ej93hq.runkit.sh
现在,剩下的就是转到 shields.io 的 JSON 端点徽章页面并粘贴 url,如下所示:

除了复制徽章 url选项外,您还可以选择复制 markdown版本,将其复制并粘贴到您的 GitHub 配置文件README中。
降价结果:

注意:您可以通过更改 RunKit 代码中的 JSON 返回语句或覆盖您要在 JSON 端点徽章页面中更改的内容来更改徽章的设计。您可以更改的属性列在同一页面上。