简体   繁体   English

如何获取《部落冲突》API?

[英]How can I fetch Clash Of Clans API?

I'm trying to do a discord bot with the clash of clans api. But I get a weird error message.我正在尝试用部落冲突 api 做一个 discord 机器人。但我收到一条奇怪的错误消息。 Thanks谢谢

Error Message:错误信息:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>v1/clans/LYVVC9JQQ</Key><RequestId>67H6BCRSJ41W6K6X</RequestId><HostId>mPhpqkXy1qKENdOnt+CPhfQn4rK0hGhaMxaLq9q21Ehtbs/CMzSgqHy9TA6L7hii0PY9+Lo2rzg=</HostId></Error>

 async function getClashofClansAPi() { let clashofClansAPI = await fetch(`https://developer.clashofclans.com/v1/clans/LYVVC9JQQ`) let cocApi = await clashofClansAPI.text() console.log(cocApi) } getClashofClansAPi()

The API URL is api.clashofclans.com and you are also lacking an API KEY in your authorization header unless you removed it for security purposes The API URL is api.clashofclans.com and you are also lacking an API KEY in your authorization header unless you removed it for security purposes

Clash of Clans API uses JSON Web Tokens for authorizing the requests.部落冲突 API 使用 JSON Web 令牌来授权请求。 Tokens are created by developers on My Account page and must be passed in every API request in Authorization HTTP header using Bearer authentication scheme.令牌由开发人员在我的帐户页面上创建,并且必须在使用承载认证方案的授权 HTTP header 中的每个 API 请求中传递。 Correct Authorization header looks like this: "Authorization: Bearer API_TOKEN".正确的授权 header 看起来像这样:“授权:承载 API_TOKEN”。

The request url should be https://api.clashofclans.com/v1/clans/%232Q8GRY8LQ请求 url 应该是https://api.clashofclans.com/v1/clans/%232Q8GRY8LQ

Remember, the hashtag (for example #2PP) should be replaced with %23, Next time, please read Clash of Clans API Documentation correctly.请记住,主题标签(例如#2PP)应替换为 %23,下次请正确阅读 Clash of Clans API 文档。

 async function getClashofClansAPi() { let clashofClansAPI = await fetch(`https://developer.clashofclans.com/v1/clans/LYVVC9JQQ`) let cocApi = await clashofClansAPI.text() console.log(cocApi) } getClashofClansAPi()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM