JS API AJAX doesn't work

7 posts

Flag Post

Hi everyone

I’m new with kongregate platform. And I have some integration problem.

I’m using HTML5 to build games – JS with jQuery.
With the existing API I can easy get username, userId ( kongregate.services.getUserId(); )
But – how to get Avatar or friends list ?
The answer is REST Function List http://developers.kongregate.com/docs/rest/authenticate.

But most of them doesn’t work with AJAX – it’s from my own experience.

The question is:
I have to make requests to the kongregate API from my server instead of the client window?
Or maybe someone know how to get Avatar url and friends list with avatars by AJAX ?

 
Flag Post

You can get avatar and friends list via the user_info JSON feed. All the other REST APIs (except badges feed) need to be done serverside or you will expose your secret game api key.

 
Flag Post

Thanks for replay UnknownGuardian.

But for me this API doesn’t work with AJAX.

JSONP example:


$.ajax({
type: “GET”,
dataType: “jsonp”,
crossDomain: true,
url: ‘http://api.kongregate.com/api/user_info.json?user_ids=1,2&callback=dupa’,
data : {},
jsonp: ‘dupa’,
success: function(result) {
console.log(“SUCCESS”);
console.log(result);
},
error: function(result) {
console.log(“ERROR”);
console.log(result);
}
});

return error: SyntaxError: invalid label

Usual AJAX call:


$.ajax({
type: “GET”,
dataType: “json”,
crossDomain: true,
url: ‘http://api.kongregate.com/api/user_info.json?user_ids=1,2’,
data : {},
success: function(result) {
console.log(“SUCCESS”);
console.log(result);
},
error: function(result) {
console.log(“ERROR”);
console.log(result);
}
});

Returns with error too.

Maybe you can show me working example of AJAX API call from JS.

 
Flag Post

I’m unfamiliar with JSONP and haven’t used Javascript as extensively as Actionscript, but is there anymore on the errors? Can you see anything in the dev panel of whatever browser you are using that looks weird?

Also, to post code, you can put it inside <pre> tags.

 
Flag Post

Thanks for your helping UnknownGuardian, I’m fixed code view.

In firebug (Firefox) and Developer Panel (Chrome) shows me that this API doesn’t work with AJAX in my shown examples.

 
Flag Post

Yes, but what errors show up? I don’t have anywhere with JSONP that I can see for myself unfortunately. (Everything throws a XMLHttpRequest cannot load http://api.kongregate.com/api/user_info.json?user_ids=1,2. Origin http://www.domain.com is not allowed by Access-Control-Allow-Origin. error)

 
Flag Post

In first case:
return error: SyntaxError: invalid label

In second case:
error 200 ok

Ok So service api.kongregate.com doesn’t support Cross Domain Call. It’s really weird for me %(