I've been trying to figure out how to use this API, but I'm not sure what it means by needing to "populate the TRN-Api-Key header with your personal API key.". Where would I do this to get results from the API? If I just try putting the API URL with all the things filled out in my browser it doesn't give me a response since I need the API key, but I can't put it in the URL (at least it's not saying anything on how/where to put it). So I was just wondering how to put the API key in so it will let me see the results?
Here's the API I'm trying to use:
BTW, I'm trying to do this with HTML and Javascript / jQuery.
I've been trying to figure out how to use this API, but I'm not sure what it means by needing to "populate the TRN-Api-Key header with your personal API key.". Where would I do this to get results from the API? If I just try putting the API URL with all the things filled out in my browser it doesn't give me a response since I need the API key, but I can't put it in the URL (at least it's not saying anything on how/where to put it). So I was just wondering how to put the API key in so it will let me see the results?
Here's the API I'm trying to use: http://docs.trnbattlefield.apiary.io/#
BTW, I'm trying to do this with HTML and Javascript / jQuery.
Share Improve this question edited Jun 27, 2023 at 17:25 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 19, 2016 at 4:35 Connor SConnor S 391 gold badge1 silver badge3 bronze badges 1-
Look at the
headers
section in the jQuery ajax documentation to send theTRN-Api-Key
header. – Rickkwa Commented Nov 19, 2016 at 5:00
2 Answers
Reset to default 1You can use jQuery's .ajax() instead of say .get(), which is just a thin wrapper around .ajax() anyway. .ajax() gives you an optional headers
parameter where you can add custom headers, such as one with your personal API key. Headers are not part of the URL address itself.
http://api.jquery./jQuery.ajax/
You can use the BF1 Tracker code examples on their site, and have many examples in different languages. As you've asked regarding jQuery, I've copied the code directly from trnbattlefield and added the api-key.
var request = new XMLHttpRequest();
request.open('GET', 'https://battlefieldtracker./bf1/api/Stats/BasicStats?
platform=3&personaId=xxxxxxxxxx&game=tunguska');
request.setRequestHeader('TRN-Api-Key', 'xxxxxxxxxxxxxxxx');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
request.send();
Note, this is using the 'DetailedStats' api.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744898980a4599864.html
评论列表(0条)