{"id":4124,"date":"2019-03-22T23:31:58","date_gmt":"2019-03-22T14:31:58","guid":{"rendered":"https:\/\/pandanote.info\/?p=4124"},"modified":"2019-03-22T23:38:44","modified_gmt":"2019-03-22T14:38:44","slug":"oauth2%e3%81%ab%e3%82%88%e3%82%8b%e8%aa%8d%e8%a8%bc%e3%82%92%e8%a1%8c%e3%81%a3%e3%81%9f%e5%be%8c%e3%80%81github-api%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f%e3%80%82","status":"publish","type":"post","link":"https:\/\/pandanote.info\/?p=4124","title":{"rendered":"OAuth2\u306b\u3088\u308b\u8a8d\u8a3c\u3092\u884c\u3063\u305f\u5f8c\u3001GitHub API\u3092\u5b9f\u884c\u3057\u3066\u307f\u305f\u3002"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p><a href=\"https:\/\/pandanote.info\/?p=3389\">\u3061\u3087\u3063\u3068\u524d\u306b\u66f8\u3044\u305f\u8a18\u4e8b<\/a>\u3067OAuth2\u8a8d\u8a3c\u3092<del datetime=\"2019-03-21T14:14:14+00:00\">\u907f\u3051\u3066\u901a\u3063\u3066<\/del>\u4f7f\u308f\u306a\u3044\u3067GitHub API\u306b\u3088\u308a\u53d6\u5f97\u3067\u304d\u308b\u60c5\u5831\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4f8b\u3068\u3057\u3066\u3001\u81ea\u5206\u304cowner\u306b\u306a\u3063\u3066\u3044\u308bGitHub\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u30b5\u30a4\u30c9\u30d0\u30fc\u306b\u8868\u793a\u3059\u308b\u30a6\u30a3\u30b8\u30a7\u30c3\u30c8\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u3053\u306e\u8a18\u4e8b\u3067\u306fOAuth2\u8a8d\u8a3c\u306e\u5f8c\u3067GitHub API\u3092\u5b9f\u884c\u3057\u305f\u7d50\u679c\u5f97\u3089\u308c\u305f\u60c5\u5831\u3068\u3001OAuth2\u8a8d\u8a3c\u306a\u3057\u3067GitHub API\u3092\u5b9f\u884c\u3057\u305f\u7d50\u679c\u5f97\u3089\u308c\u305f\u60c5\u5831\u3092\u6bd4\u8f03\u3057\u305f\u7d50\u679c\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3059\u3002\u307e\u305f\u3001GitHub API\u306e\u5229\u7528\u6642\u306bOAuth2\u8a8d\u8a3c\u3092\u884c\u3046\u305f\u3081\u306b\u306fGitHub\u306e\u30b5\u30a4\u30c8\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u767b\u9332\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u305d\u308c\u306b\u3064\u3044\u3066\u3082\u66f8\u304d\u307e\u3059\u3002<\/p>\n<h2>\u6bd4\u8f03\u306e\u5bfe\u8c61\u3068\u3059\u308b\u60c5\u5831<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u30e6\u30fc\u30b6\u306e\u60c5\u5831\u3092OAuth2\u8a8d\u8a3c\u3042\u308a\u3068\u306a\u3057\u306e2\u901a\u308a\u306e\u65b9\u6cd5\u3067\u53d6\u5f97\u3057\u3066\u3001\u305d\u306e\u7d50\u679c\u3092\u6bd4\u8f03\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<h2>OAuth2\u8a8d\u8a3c\u306a\u3057\u306e\u5834\u5408<\/h2>\n<p>OAuth2\u8a8d\u8a3c\u306a\u3057\u3067\u306eGitHub API\u306e\u5b9f\u884c\u7d50\u679c\u306fWeb\u30d6\u30e9\u30a6\u30b6\u306e\u30a2\u30c9\u30ec\u30b9\u30d0\u30fc\u306bURL\u3092\u5165\u529b\u3059\u308b\u3068\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b(\u672b\u5c3e\u306e\u30b9\u30e9\u30c3\u30b7\u30e5\u306f\u4e0d\u8981\u3067\u3059\u3002)\u3068\u2026<\/p>\n<div class=\"code\">https:\/\/api.github.com\/users\/pandanote-info<\/div>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7d50\u679c\u304c\u8fd4\u3055\u308c\u307e\u3059(\u4ee5\u4e0b\u306e\u7d50\u679c\u306f\u3053\u306e\u8a18\u4e8b\u3092\u6700\u521d\u306b\u66f8\u3044\u305f\u6642\u70b9(2019\u5e743\u6708)\u306e\u3082\u306e\u3067\u3059\u3002GitHub\u3067\u306e\u767b\u9332\u60c5\u5831\u304c\u5909\u66f4\u3055\u308c\u308b\u3068\u3001\u305d\u308c\u306b\u5fdc\u3058\u3066API\u306e\u5b9f\u884c\u7d50\u679c\u3082\u5909\u5316\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059)\u3002<\/p>\n<div class=\"code\">{<br \/>\n  &#8220;login&#8221;: &#8220;pandanote-info&#8221;,<br \/>\n  &#8220;id&#8221;: 29232018,<br \/>\n  &#8220;node_id&#8221;: &#8220;MDQ6VXNlcjI5MjMyMDE4&#8221;,<br \/>\n  &#8220;avatar_url&#8221;: &#8220;https:\/\/avatars3.githubusercontent.com\/u\/29232018?v=4&#8221;,<br \/>\n  &#8220;gravatar_id&#8221;: &#8220;&#8221;,<br \/>\n  &#8220;url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info&#8221;,<br \/>\n  &#8220;html_url&#8221;: &#8220;https:\/\/github.com\/pandanote-info&#8221;,<br \/>\n  &#8220;followers_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/followers&#8221;,<br \/>\n  &#8220;following_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/following{\/other_user}&#8221;,<br \/>\n  &#8220;gists_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/gists{\/gist_id}&#8221;,<br \/>\n  &#8220;starred_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/starred{\/owner}{\/repo}&#8221;,<br \/>\n  &#8220;subscriptions_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/subscriptions&#8221;,<br \/>\n  &#8220;organizations_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/orgs&#8221;,<br \/>\n  &#8220;repos_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/repos&#8221;,<br \/>\n  &#8220;events_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/events{\/privacy}&#8221;,<br \/>\n  &#8220;received_events_url&#8221;: &#8220;https:\/\/api.github.com\/users\/pandanote-info\/received_events&#8221;,<br \/>\n  &#8220;type&#8221;: &#8220;User&#8221;,<br \/>\n  &#8220;site_admin&#8221;: false,<br \/>\n  &#8220;name&#8221;: &#8220;pandanote-info&#8221;,<br \/>\n  &#8220;company&#8221;: null,<br \/>\n  &#8220;blog&#8221;: &#8220;https:\/\/pandanote.info\/&#8221;,<br \/>\n  &#8220;location&#8221;: &#8220;Yokohama, Japan&#8221;,<br \/>\n  &#8220;email&#8221;: null,<br \/>\n  &#8220;hireable&#8221;: true,<br \/>\n  &#8220;bio&#8221;: &#8220;write a blog which describes some computer tips and tricks mainly in Japanese.&#8221;,<br \/>\n  &#8220;public_repos&#8221;: 7,<br \/>\n  &#8220;public_gists&#8221;: 67,<br \/>\n  &#8220;followers&#8221;: 0,<br \/>\n  &#8220;following&#8221;: 0,<br \/>\n  &#8220;created_at&#8221;: &#8220;2017-06-06T14:26:53Z&#8221;,<br \/>\n  &#8220;updated_at&#8221;: &#8220;2019-02-06T14:41:42Z&#8221;<br \/>\n}<\/div>\n<p>&nbsp;<\/p>\n<p>\u7c21\u5358\u3067\u3059\u306d\u3002\ud83d\ude42<\/p>\n<h2>OAuth2\u8a8d\u8a3c\u3042\u308a\u306e\u5834\u5408<\/h2>\n<p>\u4e00\u65b9\u3001OAuth2\u8a8d\u8a3c\u306b\u3088\u308b\u8a8d\u8a3c\u5f8c\u306bGitHub API\u3092\u5b9f\u884c\u3059\u308b\u306b\u306f\u3001OAuth2\u8a8d\u8a3c\u306e\u305f\u3081\u306b\u5fc5\u8981\u306a\u60c5\u5831\u3092GitHub\u306b\u767b\u9332\u3057\u3001Client ID\u3068Client Secret\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u767b\u9332<\/h3>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u767b\u9332\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>GitHub\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u307e\u3059\u3002<\/li>\n<li>\u753b\u9762\u53f3\u4e0a\u306e\u30a2\u30d0\u30bf\u30fc\u306e\u30a2\u30a4\u30b3\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u8868\u793a\u3055\u308c\u308b\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u300cSettings\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/li>\n<li>\u5de6\u5074\u306e\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u300cDeveloper Settings\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/li>\n<li>\u753b\u9762\u304c\u5207\u308a\u66ff\u308f\u308a\u307e\u3059\u306e\u3067\u3001\u5de6\u5074\u306e\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u300cOAuth Apps\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/li>\n<li>\u753b\u9762\u53f3\u5074\u306e\u300cNew OAuth App\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u307e\u3059\u3002<\/li>\n<li>\u300cRegister a new OAuth application\u300d\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u5fc5\u8981\u4e8b\u9805\u3092\u5165\u529b\u3057\u307e\u3059\u3002\u306a\u304a\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u7528\u306eURL\u306b\u306f\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\u306a\u3082\u306e\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>\u5fc5\u8981\u4e8b\u9805\u304c\u5165\u529b\u3067\u304d\u305f\u3089\u3001\u300cRegister Application\u300d\u30dc\u30bf\u30f3(\u4e0b\u56f3\u306e\u7dd1\u8272\u306e\u30dc\u30bf\u30f3)\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/pandanote.info\/?attachment_id=4126\" rel=\"attachment wp-att-4126\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene1a-300x167.png\" alt=\"\" width=\"300\" height=\"167\" class=\"alignnone size-medium wp-image-4126\" srcset=\"https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene1a-300x167.png 300w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene1a-768x427.png 768w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene1a-1024x569.png 1024w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene1a-660x367.png 660w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene1a.png 1151w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<li>\u767b\u9332\u306b\u6210\u529f\u3059\u308b\u3068\u753b\u9762\u304c\u5207\u308a\u66ff\u308f\u308a\u3001Client ID\u53ca\u3073Client Secret\u304c\u8868\u793a\u3055\u308c\u307e\u3059(\u4e0b\u56f3\u306e\u8d64\u67a0\u5185)\u306e\u3067\u3001OAuth2\u8a8d\u8a3c\u6642\u306b\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/pandanote.info\/?attachment_id=4127\" rel=\"attachment wp-att-4127\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene4a-300x167.png\" alt=\"\" width=\"300\" height=\"167\" class=\"alignnone size-medium wp-image-4127\" srcset=\"https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene4a-300x167.png 300w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene4a-768x427.png 768w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene4a-1024x569.png 1024w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene4a-660x367.png 660w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene4a.png 1152w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<\/ol>\n<h3>request_oauthlib\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>Python3\u3067OAuth2\u306e\u8a8d\u8a3c\u306b\u3064\u3044\u3066\u306e\u60c5\u5831\u3092\u53d6\u308a\u6271\u3046\u305f\u3081\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u3057\u3066\u3001request_oauthlib\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<p>request_oauthlib\u306froot\u6a29\u9650\u3067\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"code\"># pip3 install request_oauthlib<\/div>\n<p>&nbsp;<\/p>\n<h3>Python3\u306e\u5bfe\u8a71\u30e2\u30fc\u30c9\u3067\u78ba\u8a8d<\/h3>\n<p>\u53c2\u8003\u6587\u732e\u306e\u8a18\u8ff0\u3092\u53c2\u8003\u306b\u3057\u3066\u5bfe\u8a71\u30e2\u30fc\u30c9\u3067\u52d5\u304b\u305b\u308b\u304b\u3069\u3046\u304b\u3092\u4ee5\u4e0b\u306e\u624b\u9806\u3067\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u30b7\u30a7\u30eb\u306e\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5165\u529b\u3057\u3066Enter\u30ad\u30fc\u3092\u62bc\u3057\u3001\u5bfe\u8a71\u30e2\u30fc\u30c9\u3067Python3\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002\n<div class=\"code\">$ python3<br \/>\nPython 3.7.1 (default, Nov  5 2018, 14:07:04)<br \/>\n[GCC 8.2.1 20181011 (Red Hat 8.2.1-4)] on linux<br \/>\nType &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br \/>\n&gt;&gt;&gt;<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u5bfe\u8a71\u30e2\u30fc\u30c9\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5165\u529b\u3057\u307e\u3059\u3002\u306a\u304a\u3001\u4ee5\u4e0b\u306e\u4f8b\u3067\u306fauthorize API\u306e\u767a\u884c\u6642\u306bscope\u3068\u3057\u3066user\u53ca\u3073gist\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u8907\u6570\u306escope\u3092\u6307\u5b9a\u3059\u308b\u969b\u306b\u306f\u30b9\u30da\u30fc\u30b9\u3067\u533a\u5207\u308b(URL\u7684\u306b\u306f&#8217;%20&#8217;\u3067\u533a\u5207\u308b)\u70b9\u306b\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u307e\u305f\u3001\u53c2\u8003\u6587\u732e\u306e\u4f8b\u306fPython2\u7528\u306e\u30b3\u30fc\u30c9\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u5165\u529b\u4f8b\u3067\u306fPython3\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u30b3\u30fc\u30c9\u306e\u4e00\u90e8\u3092\u5909\u66f4\u3057\u3066\u3044\u307e\u3059\u3002\n<div class=\"code\">&gt;&gt;&gt; client_id = &#8216;&lt;the id you get from github&gt;&#8217;<br \/>\n&gt;&gt;&gt; client_secret = &#8216;&lt;the secret you get from github&gt;&#8217;<\/p>\n<p>&gt;&gt;&gt; # OAuth endpoints given in the GitHub API documentation<br \/>\n&gt;&gt;&gt; authorization_base_url = &#8216;https:\/\/github.com\/login\/oauth\/authorize?user%20gist&#8217;<br \/>\n&gt;&gt;&gt; token_url = &#8216;https:\/\/github.com\/login\/oauth\/access_token&#8217;<\/p>\n<p>&gt;&gt;&gt; from requests_oauthlib import OAuth2Session<br \/>\n&gt;&gt;&gt; github = OAuth2Session(client_id)<br \/>\n&gt;&gt;&gt; # Redirect user to GitHub for authorization<br \/>\n&gt;&gt;&gt; authorization_url, state = github.authorization_url(authorization_base_url)<br \/>\n&gt;&gt;&gt; print(&#8216;Please go here and authorize,&#8217;, authorization_url)<\/p><\/div>\n<p>&nbsp;\n<\/li>\n<li>\u624b\u98062\u306e\u6700\u5f8c\u306e\u30b3\u30de\u30f3\u30c9\u304c\u6b63\u5e38\u306b\u5b9f\u884c\u3055\u308c\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001\u9069\u5f53\u306a\u30d6\u30e9\u30a6\u30b6\u3092\u7528\u3044\u3066\u6307\u793a\u3055\u308c\u305fURL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002\n<div class=\"code\">Please go here and authorize, https:\/\/github.com\/login\/oauth\/authorize?scope=user+gist&amp;response_type=code&amp;client_id=&lt;client id&gt;&amp;state=&lt;state&gt;<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u305f\u5834\u5408\u306b\u306f\u3001\u300cAuthorize\u300d\u30dc\u30bf\u30f3(\u4e0b\u56f3\u306e\u8d64\u77e2\u5370)\u3092\u62bc\u3059\u3002<br \/>\n<a href=\"https:\/\/pandanote.info\/?attachment_id=4133\" rel=\"attachment wp-att-4133\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene5a-300x166.png\" alt=\"\" width=\"300\" height=\"166\" class=\"alignnone size-medium wp-image-4133\" srcset=\"https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene5a-300x166.png 300w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene5a-768x424.png 768w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene5a-1024x566.png 1024w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene5a-660x364.png 660w, https:\/\/pandanote.info\/wordpress\/wp-content\/uploads\/2019\/03\/Gist_with_OAuth2_scene5a.png 1148w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<li>OAuth\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u767b\u9332\u6642\u306bcallback\u5148\u3068\u3057\u3066\u6307\u5b9a\u3057\u305fURL\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u305d\u306eURL\u3092\u3069\u3053\u304b\u306b\u30b3\u30d4\u30fc\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/li>\n<li>Python3\u306e\u5bfe\u8a71\u30e2\u30fc\u30c9\u306b\u623b\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5165\u529b\u3057\u307e\u3059\u3002\u3059\u308b\u3068\u3001URL\u306e\u5165\u529b\u3092\u6c42\u3081\u3089\u308c\u307e\u3059\u306e\u3067\u3001\u624b\u98065\u3067\u30b3\u30d4\u30fc\u3057\u3066\u304a\u3044\u305fURL\u3092\u30da\u30fc\u30b9\u30c8\u3057\u3001Enter\u30ad\u30fc\u3092\u62bc\u3057\u307e\u3059\u3002\n<div class=\"code\">&gt;&gt;&gt; redirect_response = input(&#8216;Paste the full redirect URL here:&#8217;)<br \/>\nPaste the full redirect URL here:<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5165\u529b\u3057\u3001Enter\u30ad\u30fc\u3092\u62bc\u3057\u307e\u3059\u3002\n<div class=\"code\">&gt;&gt;&gt; github.fetch_token(token_url, client_secret=client_secret, authorization_response=redirect_response)<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u8fd4\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u306f\u4ed6\u306e\u30d5\u30a1\u30a4\u30eb\u7b49\u306b\u30b3\u30d4\u30fc\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<div class=\"code\">{&#8216;access_token&#8217;: &#8216;some access token&#8217;, &#8216;token_type&#8217;: &#8216;bearer&#8217;, &#8216;scope&#8217;: [&#8216;gist,user&#8217;]}<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u3053\u3053\u307e\u3067\u306e\u624b\u9806\u3067OAuth2\u306b\u3088\u308b\u8a8d\u8a3c\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5165\u529b\u3057\u3066Enter\u30ad\u30fc\u3092\u62bc\u3057\u307e\u3059\u3002\n<div class=\"code\">&gt;&gt;&gt; r = github.get(&#8216;https:\/\/api.github.com\/users\/pandanote-info&#8217;)<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001\u8fd4\u3055\u308c\u305f\u6587\u5b57\u5217\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002\n<div class=\"code\">&gt;&gt;&gt; print(r.content)<\/div>\n<p>&nbsp;\n<\/li>\n<li>\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3068\u306a\u308a\u307e\u3059\u3002\u306a\u304a\u3001\u53ef\u8aad\u6027\u3092\u9ad8\u3081\u308b\u305f\u3081\u306b\u6539\u884c\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u3002\n<div class=\"code\">b'{<br \/>\n&#8220;login&#8221;:&#8221;pandanote-info&#8221;,<br \/>\n&#8220;id&#8221;:29232018,<br \/>\n&#8220;node_id&#8221;:&#8221;MDQ6VXNlcjI5MjMyMDE4&#8243;,<br \/>\n&#8220;avatar_url&#8221;:&#8221;https:\/\/avatars3.githubusercontent.com\/u\/29232018?v=4&#8243;,<br \/>\n&#8220;gravatar_id&#8221;:&#8221;&#8221;,<br \/>\n&#8220;url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info&#8221;,<br \/>\n&#8220;html_url&#8221;:&#8221;https:\/\/github.com\/pandanote-info&#8221;,<br \/>\n&#8220;followers_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/followers&#8221;,<br \/>\n&#8220;following_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/following{\/other_user}&#8221;,<br \/>\n&#8220;gists_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/gists{\/gist_id}&#8221;,<br \/>\n&#8220;starred_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/starred{\/owner}{\/repo}&#8221;,<br \/>\n&#8220;subscriptions_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/subscriptions&#8221;,<br \/>\n&#8220;organizations_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/orgs&#8221;,<br \/>\n&#8220;repos_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/repos&#8221;,<br \/>\n&#8220;events_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/events{\/privacy}&#8221;,<br \/>\n&#8220;received_events_url&#8221;:&#8221;https:\/\/api.github.com\/users\/pandanote-info\/received_events&#8221;,<br \/>\n&#8220;type&#8221;:&#8221;User&#8221;,<br \/>\n&#8220;site_admin&#8221;:false,<br \/>\n&#8220;name&#8221;:&#8221;pandanote-info&#8221;,<br \/>\n&#8220;company&#8221;:null,<br \/>\n&#8220;blog&#8221;:&#8221;https:\/\/pandanote.info\/&#8221;,<br \/>\n&#8220;location&#8221;:&#8221;Yokohama, Japan&#8221;,<br \/>\n&#8220;email&#8221;:null,<br \/>\n&#8220;hireable&#8221;:true,<br \/>\n&#8220;bio&#8221;:&#8221;write a blog which describes some computer tips and tricks mainly in Japanese.&#8221;,<br \/>\n&#8220;public_repos&#8221;:7,<br \/>\n&#8220;public_gists&#8221;:67,<br \/>\n&#8220;followers&#8221;:0,<br \/>\n&#8220;following&#8221;:0,<br \/>\n&#8220;created_at&#8221;:&#8221;2017-06-06T14:26:53Z&#8221;,<br \/>\n&#8220;updated_at&#8221;:&#8221;2019-03-22T11:08:24Z&#8221;,<br \/>\n&#8220;private_gists&#8221;:4,<br \/>\n&#8220;total_private_repos&#8221;:0,<br \/>\n&#8220;owned_private_repos&#8221;:0,<br \/>\n&#8220;disk_usage&#8221;:330,<br \/>\n&#8220;collaborators&#8221;:0,<br \/>\n&#8220;two_factor_authentication&#8221;:false,<br \/>\n&#8220;plan&#8221;:{&#8220;name&#8221;:&#8221;free&#8221;,<br \/>\n&#8220;space&#8221;:976562499,<br \/>\n&#8220;collaborators&#8221;:0,<br \/>\n&#8220;private_repos&#8221;:10000}}&#8217;<\/div>\n<p>&nbsp;\n<\/li>\n<\/ol>\n<h2>\u5f97\u3089\u308c\u305f\u60c5\u5831\u306e\u6bd4\u8f03<\/h2>\n<p>OAuth2\u8a8d\u8a3c\u3042\u308a\u306e\u5834\u5408\u306b\u5f97\u3089\u308c\u308b\u60c5\u5831\u3068\u3057\u3066\u306f\u3001OAuth2\u8a8d\u8a3c\u306a\u3057\u306e\u5834\u5408\u306b\u5f97\u3089\u308c\u308b\u60c5\u5831\u306b\u52a0\u3048\u3066\u3001\u4ee5\u4e0b\u306e\u60c5\u5831\u3092\u5f97\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<ol>\n<li>&#8220;private_gists&#8221;<\/li>\n<li>&#8220;total_private_repos&#8221;<\/li>\n<li>&#8220;owned_private_repos&#8221;<\/li>\n<li>&#8220;disk_usage&#8221;<\/li>\n<li>&#8220;collaborators&#8221;<\/li>\n<li>&#8220;two_factor_authentication&#8221;<\/li>\n<li>&#8220;plan&#8221;\n<ol>\n<li>&#8220;name&#8221;<\/li>\n<li>&#8220;space&#8221;<\/li>\n<li>&#8220;collaborators&#8221;<\/li>\n<li>&#8220;private_repos&#8221;<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u4e0a\u8a18\u306e\u51fa\u529b\u7d50\u679c\u3067\u306fprivate\u306agist\u306e\u4ef6\u6570\u304c\u51fa\u529b\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001Gist\u306f\u516c\u958b\u6642\u306bprivate\u3067\u516c\u958b\u3059\u308b\u3053\u3068\u3092\u9078\u629e\u3057\u305f\u5834\u5408\u3067\u3082URL\u304c\u308f\u304b\u3063\u3066\u3044\u308c\u3070\u30a2\u30af\u30bb\u30b9\u3067\u304d\u3066\u3057\u307e\u3046(\u672cWeb\u30b5\u30a4\u30c8\u3067\u3082private\u516c\u958b\u3057\u3066\u3044\u308bGist\u3092\u666e\u901a\u306b\u8cbc\u308a\u4ed8\u3051\u3066\u3044\u307e\u3059\u3002)\u3082\u306e\u3067\u3042\u308b\u3053\u3068\u3068\u3001\u3053\u306e\u8a18\u4e8b\u3092\u6700\u521d\u306b\u66f8\u3044\u305f\u6642\u70b9(2019\u5e743\u6708)\u3067\u306f\u7279\u306bprivate\u306b\u3059\u3079\u304d\u30d5\u30a1\u30a4\u30eb\u3092Gist\u306b\u7f6e\u3044\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u306a\u3044(\u3080\u3057\u308d\u516c\u958b\u6642\u306b\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u307e\u307eprivate\u306b\u8a2d\u5b9a\u3057\u3066\u3057\u307e\u3063\u305f\u3082\u306e\u3067\u3001\u305d\u3082\u305d\u3082public\u3067\u8a2d\u5b9a\u3057\u3066\u3082\u3088\u3044\u3082\u306e\u3067\u3057\u305f\u3002)\u306e\u3067\u3001\u7279\u306b\u96a0\u3059\u3053\u3068\u306a\u304f\u516c\u958b\u3059\u308b\u3053\u3068\u3068\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>GitHub API\u306f\u6539\u5ec3\u304c\u983b\u7e41\u306b\u884c\u308f\u308c\u308b\u305b\u3044\u304b\u3069\u3046\u304b\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u5b9f\u884c\u3057\u305f\u7d50\u679c\u5f97\u3089\u308c\u308b\u60c5\u5831\u306b\u3064\u3044\u3066\u306e\u60c5\u5831\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u5316\u304c\u5341\u5206\u3067\u306a\u3044\u3068\u601d\u3063\u305f\u306e\u3067\u3001\u3053\u306e\u8a18\u4e8b\u3092\u66f8\u304f\u3053\u3068\u3068\u3057\u307e\u3057\u305f\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u958b\u767a\u306e\u53c2\u8003\u306b\u3057\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u53d6\u5f97\u3057\u305f\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3046\u3068OAuth2\u8a8d\u8a3c\u304c\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3088\u3046\u3067\u3059\u304c\u3001\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u5225\u306e\u6a5f\u4f1a\u306b\u8a66\u305d\u3046\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306f\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n<h2>References \/ \u53c2\u8003\u6587\u732e<\/h2>\n<ul>\n<li><a href=\"https:\/\/requests-oauthlib.readthedocs.io\/en\/latest\/examples\/github.html\">GitHub OAuth 2 Tutorial<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u3061\u3087\u3063\u3068\u524d\u306b\u66f8\u3044\u305f\u8a18\u4e8b\u3067OAuth2\u8a8d\u8a3c\u3092\u907f\u3051\u3066\u901a\u3063\u3066\u4f7f\u308f\u306a\u3044\u3067GitHub API\u306b\u3088\u308a\u53d6\u5f97\u3067\u304d\u308b\u60c5\u5831\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4f8b\u3068\u3057\u3066\u3001\u81ea\u5206\u304cowner\u306b\u306a\u3063\u3066\u3044\u308bGitHub\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u30b5\u30a4\u30c9\u30d0\u30fc\u306b\u8868\u793a\u3059\u308b\u30a6\u30a3\u30b8\u30a7\u30c3\u30c8\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3057\u305f\u3002 \u305d\u3053\u3067\u3001\u3053\u306e\u8a18\u4e8b\u3067\u306fOAuth2\u8a8d\u8a3c\u306e\u5f8c\u3067GitHub API\u3092\u5b9f\u884c\u3057\u305f\u7d50\u679c\u5f97\u3089\u308c\u305f\u60c5\u5831\u3068\u3001OAuth2\u8a8d\u8a3c\u306a\u3057\u3067GitHub API\u3092\u5b9f\u884c\u3057\u2026 <span class=\"read-more\"><a href=\"https:\/\/pandanote.info\/?p=4124\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":4133,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,26,27,20,3],"tags":[],"class_list":["post-4124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-github","category-github-api","category-python3","category-website-2"],"_links":{"self":[{"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/posts\/4124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pandanote.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4124"}],"version-history":[{"count":9,"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/posts\/4124\/revisions"}],"predecessor-version":[{"id":4136,"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/posts\/4124\/revisions\/4136"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pandanote.info\/index.php?rest_route=\/wp\/v2\/media\/4133"}],"wp:attachment":[{"href":"https:\/\/pandanote.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pandanote.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pandanote.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}