Github API 征求用户帐号
Github API call for user accounts
您好,我正在尝试从 Github API 获取用户数据、他们编程的语言、他们的存储库和他们连接的 followers/follows 以及他们的号码.
我已通读文档,但没有找到任何特定于我需要的查询的内容。
目前,我已使用此查询调用 https://api.github.com/search/users?q=location:uk&sort=stars&order=desc&page=1&per_page=100
但是,这个 returns 帐户名、url 和其他与我想要实现的目标无关的东西。我在 Jupyter notebook 上使用 json 和 python 请求分析这些数据。
任何人都可以分享他们的意见,谢谢。
您可以使用 GraphQL Api v4 来请求用户提供您想要的特定信息。在以下查询中,您使用 location:uk
搜索用户并提取他们的登录名、姓名、关注者、关注者计数、存储库、存储库计数、语言等...
{
search(query: "location:uk", type: USER, first: 100) {
userCount
pageInfo {
hasNextPage
endCursor
}
nodes {
... on User {
login
name
location
repositories(first: 10) {
totalCount
nodes {
languages(first: 2) {
nodes {
name
}
}
name
}
}
followers(first: 10) {
totalCount
nodes {
login
}
}
}
}
}
}
对于分页,用first: 100
请求前100条,用after: <cursor_value>
请求下一页,cursor值为上一页的最后一个cursor,如[的值=15=] 在上一个查询中。
在 Python 中,这将是:
import json
import requests
access_token = "YOUR_ACCESS_TOKEN"
query = """
{
search(query: "location:uk", type: USER, first: 100) {
userCount
pageInfo {
hasNextPage
endCursor
}
nodes {
... on User {
login
name
location
repositories(first: 10) {
totalCount
nodes {
languages(first: 2) {
nodes {
name
}
}
name
}
}
followers(first: 10) {
totalCount
nodes {
login
}
}
}
}
}
}"""
data = {'query': query.replace('\n', ' ')}
headers = {'Authorization': 'token ' + access_token, 'Content-Type': 'application/json'}
r = requests.post('https://api.github.com/graphql', headers=headers, json=data)
print(json.loads(r.text))
您好,我正在尝试从 Github API 获取用户数据、他们编程的语言、他们的存储库和他们连接的 followers/follows 以及他们的号码.
我已通读文档,但没有找到任何特定于我需要的查询的内容。
目前,我已使用此查询调用 https://api.github.com/search/users?q=location:uk&sort=stars&order=desc&page=1&per_page=100
但是,这个 returns 帐户名、url 和其他与我想要实现的目标无关的东西。我在 Jupyter notebook 上使用 json 和 python 请求分析这些数据。
任何人都可以分享他们的意见,谢谢。
您可以使用 GraphQL Api v4 来请求用户提供您想要的特定信息。在以下查询中,您使用 location:uk
搜索用户并提取他们的登录名、姓名、关注者、关注者计数、存储库、存储库计数、语言等...
{
search(query: "location:uk", type: USER, first: 100) {
userCount
pageInfo {
hasNextPage
endCursor
}
nodes {
... on User {
login
name
location
repositories(first: 10) {
totalCount
nodes {
languages(first: 2) {
nodes {
name
}
}
name
}
}
followers(first: 10) {
totalCount
nodes {
login
}
}
}
}
}
}
对于分页,用first: 100
请求前100条,用after: <cursor_value>
请求下一页,cursor值为上一页的最后一个cursor,如[的值=15=] 在上一个查询中。
在 Python 中,这将是:
import json
import requests
access_token = "YOUR_ACCESS_TOKEN"
query = """
{
search(query: "location:uk", type: USER, first: 100) {
userCount
pageInfo {
hasNextPage
endCursor
}
nodes {
... on User {
login
name
location
repositories(first: 10) {
totalCount
nodes {
languages(first: 2) {
nodes {
name
}
}
name
}
}
followers(first: 10) {
totalCount
nodes {
login
}
}
}
}
}
}"""
data = {'query': query.replace('\n', ' ')}
headers = {'Authorization': 'token ' + access_token, 'Content-Type': 'application/json'}
r = requests.post('https://api.github.com/graphql', headers=headers, json=data)
print(json.loads(r.text))