GitHub 库信息管理 API

虽说Github有专项连接器,今天还是从API角度测试一把:
官网:https://github.com/
可以随意注册个账号玩一玩。。。
读取某个用户信息:

Json.Document(Web.Contents("https://api.github.com/users/tt0203"))

读取账户下所有库:

Table.FromRecords(Json.Document(Web.Contents("https://api.github.com/users/tt0203/repos")))

读取账户下某个库:

Json.Document(Web.Contents("https://api.github.com/repos/tt0203/pyecharts"))

查看库内容列表:

Table.FromRecords(Json.Document(Web.Contents("https://api.github.com/repos/tt0203/pyecharts/contents")))

内容根目录下某个目录文件的读取:

Text.FromBinary(Binary.FromText(Json.Document(Web.Contents("https://api.github.com/repos/tt0203/pyecharts/contents/README.en.md"))[content]))

某文件原始内容读取:

Text.FromBinary(Web.Contents("https://raw.githubusercontent.com/tt0203/pyecharts/master/.gitattributes"))

提交的commits列表:

Table.FromRecords(Json.Document(Web.Contents("https://api.github.com/repos/tt0203/pyecharts/commits")))

读取某条commit(上一步的sha值):

Json.Document(Web.Contents("https://api.github.com/repos/tt0203/pyecharts/commits/973c982ad6fa6aef51beed7637f939d8c23eae0e"))

读取issues列表:

Table.FromRecords(Json.Document(Web.Contents("https://api.github.com/repos/tt0203/-changxin/issues")))
Json.Document(Web.Contents("https://api.github.com/repos/tt0203/-changxin/issues/1"))
Table.FromRecords(Json.Document(Web.Contents("https://api.github.com/repos/tt0203/-changxin/issues/1/comments")))
Json.Document(Web.Contents("https://api.github.com/repos/tt0203/-changxin/issues/comments/690022518"))

上面接口可以加入page=页数&per_page=每页记录数,还可以指定issues状态是否关闭state=closed
授权
https://github.com/settings/apps
可以自建应用或者生成一个新的OAuth应用:
拿到Client ID和Client Secret用于token授权
也可以生成一个个人令牌用于自有账户库信息操作(注意令牌格式):

Authorization="token ********************"

添加评论:

Json.Document(Web.Contents("https://api.github.com/repos/tt0203/-changxin/issues",
[Headers=[Authorization="token 你的个人令牌"],Content=Json.FromValue([title="吹牛逼",body="施主学PQ吗"])]))

评论回复:

Json.Document(Web.Contents("https://api.github.com/repos/tt0203/-changxin/issues/1/comments",
[Headers=[Authorization="token 2d1cb16da30865b6049a96bc3e54a9559f73e90c"],Content=Json.FromValue([body="还踢球?"])]))  //这里就返回comments评论ID

filefilefilefilefilefilefilefilefilefile
增删改查不过瘾去下面走两步?

https://developer.github.com/v3/

你也可以新建Github app,通过Client ID和Client Secret授权调用:
file
file

from flask import Flask,redirect,request,json
from furl import furl
import requests

client_id='你的id'
client_secret='你的secret'
app = Flask(__name__)
@app.route('/',methods=['GET','POST'])
def fx():
    url='https://github.com/login/oauth/authorize'
    params={'client_id':client_id,'scope':'repo,admin:repo_hook,admin:org,admin:public_key,admin:org_hook,gist,notifications,user,delete_repo,write:discussion,write:packages,read:packages,delete:packages,admin:gpg_key,workflow','state':'123456','allow_signup':'true'}
    url=furl(url).set(params)
    return redirect(url,302)

#回调路由
@app.route('/oauth2/github/callback')
def fx2():
    code=request.args.get('code')
    access_token_url='https://github.com/login/oauth/access_token'
    payload={'client_id':client_id,'client_secret':client_secret,'code':code,'state':'ABC'}
    r=requests.post(access_token_url,json=payload,headers={'Accept':'application/json'})
    return json.loads(r.text)
if __name__ == '__main__':
    app.run()

浏览器地址栏输入127.0.0.1:5000登陆授权后即可返回token

道高一尺 魔高一丈
https://pbihub.cn/users/44
M与DAX的恩怨纠葛