views:

427

answers:

4

Hi guys,

Can someone please give me an example of how to access the Halo: Reach stats API

using jquery ajax?

Here is an exert:

GetGameHistory(System.String, System.String, System.String, System.String)

This function is used to browse through a player's history of games.

Parameters

identifier: Your application's identifier string. gamertag: The target player's gamertag. variant_class: The variant class of game to get. Valid values are "Campaign", > "Firefight", "Competitive", "Arena", "Invasion", "Custom". Pass "Unknown" to get all games. iPage: The page of results you want, starting at page 0.

Return Value A GameHistoryResponse object containing a list of the games matching the criteria you specified.

Example http://www.bungie.net/api/reach/reachapijson.svc /player/gamehistory/ {identifier}/{gamertag}/{variant_class_string}/{iPage}

here was my attempt:

var apikey      = 'xxx';
var gamertag    = 'The Hailwood';
var variant     = 'Competitive';
var page        = '0';
var url = 'http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/'+apikey+'/'+gamertag+'/'+variant+'/'+page;

$(document).ready(function() {
  $.ajax({
    url: url,
    success: function(data) {
      $('#return').html(data);
    }
  });
});

However I get XMLHttpRequest cannot load http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/xxx/The%20Hailwood/Competitive/0. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

What does this mean?


Update:
Ok so I fixed it by setting appropriate permissions.

But now I am getting a 400 response from the server.

Any idea what would cause this?


Update2:
API IS NOT OPERATIONAL! hence why it is not working :(

+1  A: 

This means you cant access it from a localhost url, try putting it on your server/hosting and giving it a test there. It should then work

JamesStuddart
This is actually run in a google chrome extension, so the error is `XMLHttpRequest cannot load http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/xxx/The%20Hailwood/Competitive/0. Origin chrome-extension://melchgapfmhmlefkbddmhajikciefnni is not allowed by Access-Control-Allow-Origin.`
Hailwood
I would expect this is because you are requesting the data from the extension and not from a true url. I dont know anything about chrome-ext's though.
JamesStuddart
Yeah i fixed it. I had to give the extension permission to that domain.But please see my update.
Hailwood
A: 

400 is just a generic bad request, but it's client range which means the server believes (may be lying, may be wrong) that something is wrong with your request - but it could be literally anything so it's up to the server to provide additional detail with the response to help you.

annakata
A: 

It doesn't matter what you do. As of now the API service is down.

iBotPeaches
A: 

The Halo Reach API isn't available yet to the public only founding developers pre release. Also as I was a beta tester of the API (I have tested and used the API for months pre release) the JSON isn't output as text but rather a file(of sort in a browser). So I doubt your ajax will be able to read it.

To add to that you will not want to be using Javascript to make the request as anyone and everyone will be able to see your key. AJAX isn't cross domain you need a server side language to grab make the request. Also a server would most likely load the response faster then your client(especially when you will be making various requests).

Hope this helped. If you have any other questions PM me on Bungie.net or read our wiki(under construction).

ApocalypeX