{"id":808,"date":"2024-11-07T15:21:13","date_gmt":"2024-11-07T07:21:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/808\/"},"modified":"2024-11-07T15:21:13","modified_gmt":"2024-11-07T07:21:13","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","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/808\/","title":{"rendered":"\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1096\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172977487277537.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172977487277537.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172977487277537-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172977487277537-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" 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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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\u5982\u4f55\u5728 GitHub \u4e09\u65b9\u6388\u6743\u4e2d\u6b63\u786e\u4f7f\u7528 access_token\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, { method: &#8216;GET&#8217;, headers: { &#8216;Authorization&#8217;: &#8220;Bearer &#8220;+accessToken } }) [&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-808","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/808","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=808"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/808\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}