问题描述
我的代码有效,但请求格式将在未来几个月内弃用。
建议使用Github
的新格式curl -u my_client_id:my_client_secret https://api.github.com/users/user
在接下来的几个月中,有人可以向我展示重新格式化它的正确方法吗?我已经尝试了一切。这是我尝试过的一个示例:
我的尝试无效
`-u ${this.client_id}:${this.client_secret} https://api.github.com/users/${user}`
我当前的代码
class Github {
constructor() {
// THESE ARE FAKE!!!
this.client_id = 'a71344259aec03d0cea3';
this.client_secret = 'a28202377336e199cb554bd099e6e5fe672788db';
this.repos_count = 7;
this.repos_sort = 'created: asc';
}
async getUser(user) {
const profileResponse = await fetch(
`https://api.github.com/users/${user}?client_id=${this.client_id}&client_secret=${this.client_secret}`
);
const repoResponse = await fetch(
`https://api.github.com/users/${user}/repos?per_page=${this.repos_count}&sort=${this.repos_sort}&client_id=${this.client_id}&client_secret=${this.client_secret}`
);
console.log(user);
const profile = await profileResponse.json();
const repos = await repoResponse.json();
return {
profile,repos,};
}
}
解决方法
mongoose.connection.close()
中的-u
选项使用HTTP Basic authentication。
这是使用curl
字符串,对它进行base64编码(例如user:password
=> user:password
),然后像这样将其添加到dXNlcjpwYXNzd29yZA==
请求标头中
Authorization
使用Authorization: Basic dXNlcjpwYXNzd29yZA==
时,您必须使用类似btoa()
的方式手动完成此操作
fetch