[英]How can I get json from an API url on node.js?
So I'm trying to get text from a URL, it is an api url but it doesn't have any special arguments, I can use a static link. 因此,如果我将链接放入浏览器,它是一个只有以下文本的空白页面:
{"id":"hFXuavIS2Fu5TJs9WC9M-ylckZ-o4b21inxr5h8axKtT1HSH","accountId":"TIIQ3c3YnJc96-p4ASIt7spCeICawEWiBJKwwDYDm0WUP23TlGoum2cc","puuid":"I5Lb36kGyhZTq3ypf1fqh6tk3p3xVA8-l-6_EDA4a9imdXm_uXAvVs-Prc8hkRoKzGVT0vr55kZ1lQ","name":"CH0G4TH","profileIconId":949,"revisionDate":1588735966000,"summonerLevel":49}
或根据用户名不同。
我尝试将 jquery 用于节点,但它需要 jsdom,我根本无法让它工作,我收到错误Error: Cannot find module './jsdom/living/generated/utils.js'
。
并且使用 XMLHttpRequest,我不明白。 站点显示调用 json 内部的特定内容,但我不想要那个,只是整个事情,所以跳过它并直接转到.send,它返回未定义。
这是我从网站上复制下来的:
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var getJSON = function(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
//(xhr.onload removed here because it was used for returning a callback, which I don't need.)
xhr.send();
}
console.log(getJSON('url'))
当然它返回未定义。
所以我不知道,我不是编码员,所以我在这里很困惑。 如果这真的很基本,我很抱歉,我只是被智障了。
我将假设这是来自您提供的 json 的防暴游戏 API(CH0G4TH,SummonerID)。
-
有很多库/模块可以用于 riotsAPI,但我建议:LeagueJS(很多其他的都是垃圾)。 既然您说您不是编码员,我建议您使用它而不是自己弄清楚,这样会容易得多。
您将需要一个 riot-api 密钥,您可以从此链接获得:
https://developer.riotgames.com/
const LeagueJS = require('leaguejs'); // Here you should put your RGAPI code const leagueJs = new LeagueJS("RGAPI-SylasReallyBeBrokenRn"); // I like to create a region variable (makes it easier to change later on) const region = "oce" // although you dont need to have a user variable I will be using one for example purposes const user = "AIIChat" // Here I can get entries by name. It returns a body which I will log leagueJs.Summoner.gettingByName(user, region).then(user => { console.log(user) }) // Returns {......}
(他们真的没有文档)
冠军端点
- gettingRotations
ChampionMasteryEndpoint
- gettingBySummoner - gettingScoresBySummoner
联赛端点
- gettingChallengerLeague - gettingMasterLeague - gettingGrandMasterLeague - gettingLeagueById - gettingEntriesForSummonerId - gettingLeagueEntriesForSummonerId - gettingEntries
LolStatus端点
- gettingShardData
匹配端点
- gettingById - gettingTimelineById - gettingListByAccount - gettingListByAccountWithoutPagination - gettingRecentListByAccount - gettingIdsByTournament - gettingByIdForTournament
观众端点
- gettingActiveGame - gettingFeaturedGames
SummonerEndpoint
- gettingByName - gettingByAccount - gettingById - gettingByPUUID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.