暴雪刚刚关闭了他们的旧API,并进行了更改,因此您需要一个apikey。我将URL更改为新的api,并添加了API密钥。我知道URL有效。
var toonJSON = UrlFetchApp.fetch("eu.api.battle.net/wow/character/"+toonRealm+"/"+toonName+"?fields=items,statistics,progression,talents,audit&apikey="+apiKey, {muteHttpExceptions: true})
var toon = JSON.parse(toonJSON.getContentText())
JSON.pase只返回一个空对象
return toon.toSorce() // retuned ({})
我用了很多时间来看看我是否能找到问题所在。空了。认为它与“responce标题”有关。
响应标题:http://pastebin.com/t30giRK1(我从dev.battle.net获取它们(暴雪api网站) JSON:http://pastebin.com/CPam4syG
答案 0 :(得分:0)
我认为这是您正在使用的代码。 我可以打开你的pastebin JSON http://pastebin.com/raw/CPam4syG的原始网址来解析它 并使用以下代码
var text = document.getElementsByTagName('pre')[0].innerHTML;
var parse = JSON.parse(text);
总而言之,我认为UrlFetchApp.fetch
正在返回{}
答案 1 :(得分:0)
所以我发现了问题:
答案 2 :(得分:0)
是同样的问题,这适用于我(别忘了粘贴你的密钥)
var toonJSON = UrlFetchApp.fetch("https://eu.api.battle.net/wow/character/"+toonRealm+"/"+toonName+"?fields=items%2Cstatistics%2Cprogression%2Caudit&locale=en_GB&apikey= ... ")