我目前正在使用纯香草javascript开发API项目, 并尝试使用异步等待从genius API中获取数据,但是当我通过控制台记录消息时,此错误不断弹出。...401此调用需要访问令牌。
但是我的脚本中有访问令牌。请我帮忙
class Github {
constructor() {
//this.client_id='383fc80f5033a1ac7313';
//this.client_secret='0cf1bdc092afd11bafc75358ae802ecba334cf36';
this.client_Token = 'C8x4l2bA37GvMPjApYyzS70Qn_Nw1yi9TO2wRExZydToj_IRXWz5AvrNhLbXWK9-';
}
async getUser() {
const lyricsResponse = await fetch(`https://api.genius.com/search?access_token=${this.client_Token}`);
const lyrics = await lyricsResponse.json();
return {
lyrics
}
}
}
const genius = new Github;
const searchUser = document.getElementById('searchUser');
// Search input event listener
searchUser.addEventListener('keyup', (e) => {
// Get input text
const userText = e.target.value;
console.log(userText);
if (userText !== '') {
//make an http call from genius(this is directly connected to genius)
genius.getUser(userText)
.then(data => {
console.log(data);
})
} else {
// Clear profile
ui.clearProfile();