我构建了一个不和谐的机器人,我想查询IGDB的搜索游戏,并返回一些信息。无论我搜索什么或更改什么,我现在只是得到了“未定义的”。
我使用CORS-anywhere作为代理。不确定这是不是问题所在。如何让响应像Postman一样在控制台中显示数据?
下面是我的代码:
client.on('message', (message) => {
if (message.author.bot) return;
if (message.content.startsWith(PREFIX)) {
const [CMD_NAME, ...args] = message.content
.trim()
.substring(PREFIX.length)
.split(/\s+/);
if (CMD_NAME === 'search') {
if (args.length === 0) return message.reply('Please provide a game.');
// Perform a GET request from the IGDB API through the cors-anywhere proxy.
const proxyUrl = 'https://cors-anywhere.herokuapp.com/'
axios({
url: `${proxyUrl}https://api-v3.igdb.com/games`,
method: 'POST',
headers: {
'Origin': 'https://api-v3.igdb.com/games',
'Accept': 'application/json',
'user-key': process.env.IGDB_USER_KEY
},
data: `fields name,first_release_date,platforms,cover,summary;search ${args};sort popularity desc;limit 1;`
})
.then(response => {
console.log(response.data);
})
.catch(err => {
console.log(err.response.request._response);
})
}
}
})```发布于 2020-10-29 08:27:05
我也在从事igdb的工作,而且是个新手。如果我错了,请告诉我,我会删除这个:D
我认为既然twitch auth是必需的,那么头部应该是不同的。您必须调用https://id.twitch.tv/oauth2/token?才能获得一个access_token,然后可以将该your与您的client_id一起传递到请求的头部。
现在您已经有了客户端ID和客户端密钥,您将使用oauth2作为
开发人员进行身份验证。详细信息可以在Twitch开发人员文档中找到。
这样做将为您提供一个访问令牌,用于将来对我们的API的请求。
使用以下查询字符串参数向https://id.twitch.tv/oauth2/token发出POST请求,并相应地替换您的客户端ID和客户端密码。
client_id=Client ID
client_secret=Client Secret
grant_type=client_credentials
headers: {
'Accept': 'application/json',
'Client-ID':'your_client_id',
'Authorization':'Bearer access_token'
},https://stackoverflow.com/questions/63713192
复制相似问题