如何从 GitHub API 中获取所有信息
How can I get all the information from the GitHub API
我有一个问题。我在 public GitHub API 上使用 vanilla JavaScript 发出 GET 请求,我得到了响应,但不是关于单个用户的完整信息。我怎样才能获得所有信息,例如 Twitter 用户名或 Twitter 帐户 link?
我对每个用户的唯一回应:
这是我的代码以防万一:
function loadUsers() {
const xhr = new XMLHttpRequest();
const URL = 'https://api.github.com/users';
xhr.open('GET', URL, true);
xhr.onload = function() {
if(this.status == 200) {
let users = this.responseText;
console.log(users);
}
}
xhr.send();
}
对于每个用户,您都会收到一个 url 以获取更多详细信息 api。在您的示例中,第一个用户有
{
...
"url": "https://api.github.com/users/mojombo",
...
},
或者只遵循架构 https://api.github.com/users/{username}
如果您调用此 url (try),您将获得 twitter 帐户和更多内容。
{
"login": "mojombo",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mojombo",
"html_url": "https://github.com/mojombo",
"followers_url": "https://api.github.com/users/mojombo/followers",
"following_url": "https://api.github.com/users/mojombo/following{/other_user}",
"gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
"organizations_url": "https://api.github.com/users/mojombo/orgs",
"repos_url": "https://api.github.com/users/mojombo/repos",
"events_url": "https://api.github.com/users/mojombo/events{/privacy}",
"received_events_url": "https://api.github.com/users/mojombo/received_events",
"type": "User",
"site_admin": false,
"name": "Tom Preston-Werner",
"company": "@chatterbugapp, @redwoodjs, @preston-werner-ventures ",
"blog": "http://tom.preston-werner.com",
"location": "San Francisco",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": "mojombo",
"public_repos": 62,
"public_gists": 62,
"followers": 22447,
"following": 11,
"created_at": "2007-10-20T05:24:19Z",
"updated_at": "2021-03-18T22:50:53Z"
}
我有一个问题。我在 public GitHub API 上使用 vanilla JavaScript 发出 GET 请求,我得到了响应,但不是关于单个用户的完整信息。我怎样才能获得所有信息,例如 Twitter 用户名或 Twitter 帐户 link?
我对每个用户的唯一回应:
这是我的代码以防万一:
function loadUsers() {
const xhr = new XMLHttpRequest();
const URL = 'https://api.github.com/users';
xhr.open('GET', URL, true);
xhr.onload = function() {
if(this.status == 200) {
let users = this.responseText;
console.log(users);
}
}
xhr.send();
}
对于每个用户,您都会收到一个 url 以获取更多详细信息 api。在您的示例中,第一个用户有
{
...
"url": "https://api.github.com/users/mojombo",
...
},
或者只遵循架构 https://api.github.com/users/{username}
如果您调用此 url (try),您将获得 twitter 帐户和更多内容。
{
"login": "mojombo",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mojombo",
"html_url": "https://github.com/mojombo",
"followers_url": "https://api.github.com/users/mojombo/followers",
"following_url": "https://api.github.com/users/mojombo/following{/other_user}",
"gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
"organizations_url": "https://api.github.com/users/mojombo/orgs",
"repos_url": "https://api.github.com/users/mojombo/repos",
"events_url": "https://api.github.com/users/mojombo/events{/privacy}",
"received_events_url": "https://api.github.com/users/mojombo/received_events",
"type": "User",
"site_admin": false,
"name": "Tom Preston-Werner",
"company": "@chatterbugapp, @redwoodjs, @preston-werner-ventures ",
"blog": "http://tom.preston-werner.com",
"location": "San Francisco",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": "mojombo",
"public_repos": 62,
"public_gists": 62,
"followers": 22447,
"following": 11,
"created_at": "2007-10-20T05:24:19Z",
"updated_at": "2021-03-18T22:50:53Z"
}