{"id":48908,"date":"2024-12-02T15:10:11","date_gmt":"2024-12-02T07:10:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48908\/"},"modified":"2024-12-02T15:10:11","modified_gmt":"2024-12-02T07:10:11","slug":"github-%e4%b8%89%e6%96%b9%e7%99%bb%e5%bd%95-access_token-%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a1%ae%e4%bd%bf%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48908\/","title":{"rendered":"GitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>GitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241103\/173061149167270923223cc.jpg\" class=\"aligncenter\" title=\"GitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f\u63d2\u56fe\" alt=\"GitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u4e2d access_token \u4f7f\u7528\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 github \u8fdb\u884c\u4e09\u65b9\u767b\u5f55\u65f6\uff0c\u5c06 access_token \u653e\u7f6e\u4e8e\u8bf7\u6c42\u5934\u7684&#8217;authorization&#8217;\u5b57\u6bb5\u4e2d\uff0c\u5374\u65e0\u6cd5\u6210\u529f\u83b7\u53d6\u7528\u6237\u4ee4\u724c\u3002<\/p>\n<p>\u6839\u636e github \u6388\u6743\u6587\u6863\uff0c\u6b63\u786e\u7684\u6388\u6743\u5934\u90e8\u5e94\u4e3a&#8221;authorization: bearer {access_token}&#8221;\u3002\u8c03\u6574\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>\u53ea\u9700\u8981\u5728 authorization \u5934\u90e8\u503c\u524d\u589e\u52a0 &#8220;bearer &#8221; \u524d\u7f00\u5373\u53ef\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/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>GitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f \u6536\u85cf \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300aGitHub \u4e09\u65b9\u767b\u5f55 access_token \u5982\u4f55\u6b63\u786e\u4f7f\u7528\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u4e2d access_token \u4f7f\u7528\u95ee\u9898 \u5728\u4f7f\u7528 github \u8fdb\u884c\u4e09\u65b9\u767b\u5f55\u65f6\uff0c\u5c06 access_token \u653e\u7f6e\u4e8e\u8bf7\u6c42\u5934\u7684&#8217;authorization&#8217;\u5b57\u6bb5\u4e2d\uff0c\u5374\u65e0\u6cd5\u6210\u529f\u83b7\u53d6\u7528\u6237\u4ee4\u724c\u3002 \u6839\u636e github \u6388\u6743\u6587\u6863\uff0c\u6b63\u786e\u7684\u6388\u6743\u5934\u90e8\u5e94\u4e3a&#8221;authorization: bearer {access_token}&#8221;\u3002\u8c03\u6574\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 &#8221; + 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-48908","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48908","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=48908"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48908\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}