GitHub API调用

1、登陆验证

调用api有两张认证方式:

账号:密码 登陆

token 授权登陆

2、使用token登陆

 

GitHub API调用_第1张图片

GitHub API调用_第2张图片

GitHub API调用_第3张图片

GitHub API调用_第4张图片

GitHub API调用_第5张图片

GitHub API调用_第6张图片

GitHub API调用_第7张图片

把生成的token粘贴出来就行,我的已经生成了,所以显示的名字和权限,但是第一次生成的不是,是一串字符

2、把token添加进header

headers={    
    'User-Agent':'Mozilla/5.0',    
    'Authorization':'token 4d5655c8676ccf607e7d0c71eb8493d5fb346e6d',              

    'Content-Type':'application/json', 
    'method':'GET',
    'Accept':'application/json'
}

注意:Authorization后面token必须加上,否则会403

3、调用API的url验证

url = "https://api.github.com"

reponse = requests.get(url,headers=headers)

验证

print(reponse.reason)
print(reponse.status_code)

4、调用seacherAPI

url2 = "https://api.github.com/search/users?q="+key

验证取值

result = requests.get(url2,headers)
count = result.json()
total = count["total_count"]
print(total)

5、调用seacher/repositoriesAPI

https://api.github.com/search/repositories?q=test123

后面可以加language:assembly&sort=stars&order=desc(语言:assembly)

GitHub API调用_第8张图片

 

调用返回值都是test123的

codeAPI不支持只进行q关键字全局搜索

https://developer.github.com/changes/2013-10-18-new-code-search-requirements/

你可能感兴趣的:(GitHub API调用)