{"id":48882,"date":"2024-12-02T08:09:23","date_gmt":"2024-12-02T00:09:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48882\/"},"modified":"2024-12-02T08:09:23","modified_gmt":"2024-12-02T00:09:23","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-github-%e4%b8%89%e6%96%b9%e6%8e%88%e6%9d%83%e4%b8%ad%e6%ad%a3%e7%a1%ae%e4%bd%bf%e7%94%a8-access_token%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48882\/","title":{"rendered":"\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241102\/17305353466725dfb29f015.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>github\u4e09\u65b9\u6388\u6743\u767b\u5f55 access_token\u4f7f\u7528\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u5229\u7528 github \u8fdb\u884c\u4e09\u65b9\u767b\u5f55\u65f6\uff0c\u5c06 access_token \u653e\u5230\u8bf7\u6c42\u5934&#8217;authorization&#8217;\u5b57\u6bb5\u53ef\u80fd\u5bfc\u81f4\u83b7\u53d6\u7528\u6237\u4ee4\u724c\u5931\u8d25\u3002github \u6388\u6743\u6587\u6863\u8bf4\u660e\uff0c\u5e94\u4f7f\u7528\u6307\u5b9a\u683c\u5f0f\u8bbe\u7f6e authorization \u5b57\u6bb5\u3002<\/p>\n<p><strong>\u6388\u6743\u5934\u683c\u5f0f<\/strong><\/p>\n<p>\u6b63\u786e\u7684 authorization \u5934\u683c\u5f0f\u5e94\u4e3a\uff1a&#8221;bearer {access_token}&#8221;\uff0c\u5176\u4e2d {access_token} \u4e3a github \u9881\u53d1\u7684\u4ee4\u724c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u4fee\u6539\u4ee3\u7801\u4e2d\u7684&#8217;authorization&#8217;\u5934\u8bbe\u7f6e\uff0c\u5c06 access_token \u4f7f\u7528\u6b63\u786e\u7684\u683c\u5f0f(<strong>bearer {access_token}<\/strong>)\u8fdb\u884c\u8bbe\u7f6e\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>private async getGithubUserInfo(accessToken) {\n    const {ctx} = this;\n    \/\/ \u4f7f\u7528accessToken\u53bb\u83b7\u53d6\u8d44\u6e90  GET https:\/\/api.github.com\/user\n    const baseURL = 'https:\/\/api.github.com\/user';\n    let res = await ctx.curl(baseURL, {\n      method: 'GET',\n      headers: {\n        'Authorization': \"Bearer \"+accessToken\n      }\n    })\n    console.log(res);\n  }<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528\u6b63\u786e\u7684authorization\u5934\u683c\u5f0f\uff0c\u53ef\u4ee5\u89e3\u51b3access_token\u65e0\u6548\u7684\u95ee\u9898\uff0c\u4ece\u800c\u6210\u529f\u83b7\u53d6\u7528\u6237\u7684\u4ee4\u724c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f \u6536\u85cf \u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01 github\u4e09\u65b9\u6388\u6743\u767b\u5f55 access_token\u4f7f\u7528\u95ee\u9898 \u5728\u5229\u7528 github \u8fdb\u884c\u4e09\u65b9\u767b\u5f55\u65f6\uff0c\u5c06 access_token \u653e\u5230\u8bf7\u6c42\u5934&#8217;authorization&#8217;\u5b57\u6bb5\u53ef\u80fd\u5bfc\u81f4\u83b7\u53d6\u7528\u6237\u4ee4\u724c\u5931\u8d25\u3002github \u6388\u6743\u6587\u6863\u8bf4\u660e\uff0c\u5e94\u4f7f\u7528\u6307\u5b9a\u683c\u5f0f\u8bbe\u7f6e authorization \u5b57\u6bb5\u3002 \u6388\u6743\u5934\u683c\u5f0f \u6b63\u786e\u7684 authorization \u5934\u683c\u5f0f\u5e94\u4e3a\uff1a&#8221;bearer {access_token}&#8221;\uff0c\u5176\u4e2d {access_token} \u4e3a github \u9881\u53d1\u7684\u4ee4\u724c\u3002 \u89e3\u51b3\u65b9\u6cd5 \u4fee\u6539\u4ee3\u7801\u4e2d\u7684&#8217;authorization&#8217;\u5934\u8bbe\u7f6e\uff0c\u5c06 access_token \u4f7f\u7528\u6b63\u786e\u7684\u683c\u5f0f(bearer {access_token})\u8fdb\u884c\u8bbe\u7f6e\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a private async getGithubUserInfo(accessToken) { const {ctx} = this; \/\/ \u4f7f\u7528accessToken\u53bb\u83b7\u53d6\u8d44\u6e90 GET https:\/\/api.github.com\/user const baseURL = &#8216;https:\/\/api.github.com\/user&#8217;; let res = await ctx.curl(baseURL, { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48882","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48882"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48882\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}