解决了 感谢Dimu Designs的帮助。
以下作品。
函数myFunction(){var url =“ https://api.fortnitetracker.com/v1/profile/pc/Ninja ”; var apiKey =“ xxx-xxx-xxx”;
var res = UrlFetchApp.fetch(url,{“ headers”:{“ TRN-Api-Key”:apiKey}});var content = res.getContentText(); Logger.log(res); Logger.log(内容);
}
问题
我正在尝试使用Google表格中的Google App脚本来调用外部Fortnite API以请求播放器数据。我停留在如何在传递请求时添加API密钥作为标头的问题。
这是我到目前为止构建的(请不要笑)!
函数myFunction(){var res = UrlFetchApp.fetch(“ https://api.fortnitetracker.com/v1/profile/PC/Ninja?”); var content = res.getContentText(); Logger.log(res);
Logger.log(内容); }
当我尝试运行此命令时,出现以下错误:
请求失败 https://api.fortnitetracker.com/v1/profile/PC/Ninja吗?返回代码401。服务器响应被截断:{“ message”:“在请求中未找到API密钥”}(使用MutantHttpExceptions选项检查完整响应
我已经尝试过根据许多不同的帖子以多种方式添加我的API密钥,但这是行不通的,只会使我更加困惑(在这一点上很容易做到)。
有谁知道我如何才能完成脚本以确保获得信息?:)
- -编辑 - -
首先,感谢帮助人员,这是我们目前的位置。我现在尝试了以下方法:
var url =“ https://api.fortnitetracker.com/v1/profile/pc/Ninja ”; var apiKey =“ xxx-xxxx-xxx”;
var response = UrlFetchApp.fetch(url,{“ headers”:{“ TRN-Api-Key”:apiKey}});
这次返回的是403错误,而不是401错误。
请注意,我还尝试使用“基本”对标头进行身份验证,但这不起作用。