APIs

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

APIs

Post by Torniquet »

What would be the best way to develope a basic read only API to get user information to be displayed and used (from the database) on another website?

I have been looking for some decent AJAX tutorials to produce one (as i think they will probably be the safest) but there is no way of turning the returned values into php variable arrays / objects. (if there is i havnt found it)

The only sane solution i can find is php cURL. But this would mean that anyone wanting to use the API would need to have a cURL enabled host.

Is there any other ways i can do this?

The goal is to make an API in which a class script can be included and initialized, or somekind of source link in which a user can add their access key etc to in order to access it.

It really needs to be able to return a php array or object. Unless someone can suggest a way of doing it through ajax.

ta muchly

nighty night xx
New Site Coming Soon! Stay tuned :D
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: APIs

Post by Jackolantern »

So the key problem here is to get a value from AJAX into a PHP object? That would only require a simple variable assignment in the AJAX's called PHP script. However, I am thinking I am missing part of the issue here.
The indelible lord of tl;dr
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: APIs

Post by Xaleph »

You are looking for JSONP. JSON is used mostly in the same domain environment, however, JSONP is used often for crossdomain.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: APIs

Post by hallsofvallhalla »

My javascript tutorial uses a simple method to use ajax to retrieve PHP arrays and data. Just build from it. I hate JSON, makes no sense to me when it is soo simple to just use standard data and split it.
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: APIs

Post by Xaleph »

Why bother splitting data from PHP and later on, in your JS doing heavy string operations? A JSON object is almost the same as a JS object, in fact, there are few differences. It`s a big array with objects inside of it. You can loop through them as simple as for(obj in jsonObj){ /*do something */ }

Ohhwell, i`m not to judge anyway, i picked up JS last month lol. My Js knowledge in raw js is limited.
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: APIs

Post by Torniquet »

thanks halls ill look at your tuts and see what i can find :)

@Xaleph

I have never really used JS let alone JSON and never heard of JSONP lol. you got any links to simple tuts which show you how to use it effectivly?

thanks for the input guys :)
New Site Coming Soon! Stay tuned :D
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: APIs

Post by Xaleph »

User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: APIs

Post by Chris »

hallsofvallhalla wrote:I hate JSON
What, that's like saying "I hate JavaScript" all JSON is is an array in JavaScript.

An array:

Code: Select all

Array ( [foo] => bar )
The array in PHP:

Code: Select all

$array = array( 'foo' => 'bar' );
 
in JavaScript:

Code: Select all

var array = new Array( 'foo' => 'bar' );
or

Code: Select all

var array = { 'foo' : 'bar' }; // actually an object, array would be [ 'foo' : 'bar' ]
PHP seralized array:

Code: Select all

a:1:{s:3:"foo";s:3:"bar";}
What this is saying, array with one value key is a string with 3 characters: 'foo' and has the value of a string 3 with characters: 'bar'.

JSON

Code: Select all

{"foo":"bar"}
Wait, which one is the shortest here? I think it's JSON(JavaScript(ECMAScript)).
Fighting for peace is declaring war on war. If you want peace be peaceful.
dave3460
Posts: 117
Joined: Wed Jul 01, 2009 2:13 pm

Re: APIs

Post by dave3460 »

i have sorted a api feed out .

i use the api address that i was given and then the key . and sort it in a sql database and then just show what info i require .

If this is what you are on about i can post how i did it .

if you want this side or was you after the create the api side so others can use the info?

Dave
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: APIs

Post by Torniquet »

well both really, but mainly the side the client will use to access my site to gather user information
New Site Coming Soon! Stay tuned :D
Post Reply

Return to “General Development”