Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub API 纪录 #115

Open
yanyue404 opened this issue Dec 30, 2019 · 0 comments
Open

GitHub API 纪录 #115

yanyue404 opened this issue Dec 30, 2019 · 0 comments

Comments

@yanyue404
Copy link
Owner

yanyue404 commented Dec 30, 2019

前言

纪录GitHub API 的使用方式,便于改造 blog。

获取 GitHub Token

点击 这里,勾选以下两项:

read: user        Read all user profile data
user: email       Access user email addresses (read-only)

⚠️警告️:别的不要勾选,以免造成账号安全问题。

如果你的项目是属于一个组织的,还需要勾选一个权限:

read: org         Read org and team membership

GitHub Token 进行 Base64 加密

打开 Chrome 的 Console,运行:

window.btoa('{你的 GitHub Token}')

如果你把 Token 直接明文推到 GitHub 仓库中,此 Token 就会立马失效,所以需要加密混淆。

在 node.js 环境中,借助 Buffer

console.log(Buffer.from("Hello World!").toString("base64"));
console.log(Buffer.from("Hello World!", "base64").toString());

axios 请求 utils

import axios from 'axios';

const axiosInstance = axios.create({
  baseURL: 'https://api.github.com',
  headers: {
    Accept: 'application/vnd.github.v3.html',
    Authorization: `token ${window.atob(accessToken)}`,
  },
});

API

  • 用户信息 https://api.github.com/users/yanyue404
  • Issues 文件 https://api.github.com/repos/yanyue404/blog/issues/114
  • 所有 Issues:https://api.github.com/repos/yanyue404/blog/issues?state=open
  • stars 列表 https://api.github.com/users/yanyue404/starred

参考链接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant