Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   What the &*%^ API's? (https://www.warriorforum.com/programming/699566-what-apis.html)

brentb 22nd October 2012 11:15 PM

What the &*%^ API's?
 
I know php pretty well but have never set up an API. I know I know, can't believe I have survived so long. Not a lot of great documentation that I could find that is basic so I can 'get' the concept. But more in depth than API secret then server sends info to server and then back.

What i do know about communicating to other servers is this:

1. You can access other server scripts by just doing <img> or <iframe> to the code with appended variables.

2. You can submit via cURL.

How does it work in API to communicate back and forth? I am pretty sure its not either of these ways.

Also if there is a very simple API for facebook or twitter or something easy for me to learn on, any suggestions appreciated.

tajimd 23rd October 2012 12:53 AM

Re: What the &*%^ API's?
 
When using img or iframe, what happens is, the other server sends you fully formatted output which you can just plug into your own site.

When using API.. the other server sends the output result in JSON or XML format which you have to then format using your own PHP, HTML and output into your site.

So, if you know PHP then go ahead and learn how to output JSON and XML results in PHP and once you know that then it becomes pretty easy to work with any API.

SteveSRS 23rd October 2012 01:58 AM

Re: What the &*%^ API's?
 
IMG and iframe has really nothing to do with API's.

API's can be XML, JSON (as mentioned before) but also plain text, your own protocol, using the full array of webserver commands (GET, POST, PUT, DELETE).

The most simple api setup would be:
www.server.com/api.php?command=getdata

Where you would be using $_GET for data input and just echo data out to reply.
Of course this is NOT the recommended method and you must ALWAYS verify input data and never trust it.

Recommended: JSON-RPC - works awesome!

eminc 23rd October 2012 04:39 AM

Re: What the &*%^ API's?
 
Hey,

API works just like normal PHP code, difference being that you can input/output using any other programming language. Mostly conversion tracking and other things are done by Javascript, so people prefer using JSON as one of the methods of passing variables.

You can make api work like this:

1) Let the user get authenticated by putting a request, something like:

http://yoursite.com/api/auth.php?una...&secret=secret

2) at the auth.php file, authenticate them, and set session variables, User's IP and Username and give them a token (a random string ). Store that token in session variable too.

3) For all the other request they make, verify the token, and the IP Address for the request, and get on with the query. Note that you may have to set a time out for their session too

Just kept it simple, you can obviously add some other things to make it more secure ;)

iframes and img tags are just the same, they access the same script, get the same thing done. Some are used for a particular task e.g. iframes for displaying buttons that involve interaction on some other domain(facebook likee, tweet), img tags for pixel tracking etc.


Mohit

viescripts 23rd October 2012 04:52 AM

Re: What the &*%^ API's?
 
For APIs CURL is used anyway.

There's a param for CURL curl_setopt:
CURLOPT_RETURNTRANSFER

If this param is set as true, the curl_exec command returns back the output.

Now the API owner decides what format they print data on their side plain text, JSON, XML etc.

brentb 23rd October 2012 07:22 AM

Re: What the &*%^ API's?
 
So to request the API I should use cURL to make the request and grab the output, however I should be prepared for a json or xml output?

Thats basically API101 in a nutshell?

SteveJohnson 23rd October 2012 09:26 AM

Re: What the &*%^ API's?
 
Quote:

Originally Posted by brentb (Post 7220797)
So to request the API I should use cURL to make the request and grab the output, however I should be prepared for a json or xml output?

Thats basically API101 in a nutshell?

No. That's not API101 in a nutshell.

First, read this: Application programming interface - Wikipedia, the free encyclopedia

You'll see that an API is nothing other than a set of rules that a site sets up in order to allow access to some portion of its stored data or functionality. Nothing more. A site publishes directions on how its API works - you follow those instructions when you're programming whatever it is you're using their data for.

HOW you access that data or functionality is up to the author of the API. Some sites let you make a simple HTTP request to a certain URL using GET: http://somesite.com?param1=all&param2=none

Some make you use POST requests.

Either can be accomplished within your own script by using cURL, if you're using PHP. You make the request, get the response, and do something with it.

The key is, you ALWAYS know what form and structure the response will have, because the sponsoring site has told you in its description of its API. You never have to guess, you never have to 'be prepared for json or xml output'.

Check the Amazon Product Advertising API at https://affiliate-program.amazon.com...tail/main.html, or PayPal's x.com for places to get your feet wet.

viescripts 25th October 2012 08:25 AM

Re: What the &*%^ API's?
 
Quote:

Originally Posted by brentb (Post 7220797)
So to request the API I should use cURL to make the request and grab the output, however I should be prepared for a json or xml output?

Thats basically API101 in a nutshell?

yes, this is the basic idea of API.
You post to API via CURL by POST or GET method a series of variables and values: API passphrase, some other data and get back from them the result, then just decode it.

All try to make now API as a set of standards, but all basicly work the same way.

viescripts 25th October 2012 08:28 AM

Re: What the &*%^ API's?
 
Quote:

Originally Posted by SteveJohnson (Post 7221506)
No. That's not API101 in a nutshell.

First, read this: Application programming interface - Wikipedia, the free encyclopedia

You'll see that an API is nothing other than a set of rules that a site sets up in order to allow access to some portion of its stored data or functionality. Nothing more. A site publishes directions on how its API works - you follow those instructions when you're programming whatever it is you're using their data for.

HOW you access that data or functionality is up to the author of the API. Some sites let you make a simple HTTP request to a certain URL using GET: http://somesite.com?param1=all&param2=none

Some make you use POST requests.

Either can be accomplished within your own script by using cURL, if you're using PHP. You make the request, get the response, and do something with it.

The key is, you ALWAYS know what form and structure the response will have, because the sponsoring site has told you in its description of its API. You never have to guess, you never have to 'be prepared for json or xml output'.

Check the Amazon Product Advertising API at https://affiliate-program.amazon.com...tail/main.html, or PayPal's x.com for places to get your feet wet.

formally we can call API - any post or get action in our browser window :)

FirstSocialApps 25th October 2012 09:42 AM

Re: What the &*%^ API's?
 
Some half correct info here posted by the other users:

API = Application Programmers Interface , in the context of web development its just a set of 'rules' to interact with another site. Nothing more.

Glen Barnhardt 25th October 2012 02:50 PM

Re: What the &*%^ API's?
 
Wow, Yes an API is simply a Application Programmers Interface. How it works depends on the site offering the API. The goal often being to receive data and sometimes update.

The reason for an API is to allow programming that interacts with the other systems Site. Google for instance has API's for a number of things.

The Google Maps API allows you to create Maps on your site. You send information about a location and it sends you information back to build the map.

I've worked with API's on Facebook, Twitter, Google, Aweber, PayPal, Authorize.Net, and at this point I can't even remember the rest. But not one of them works exactly the same. So you have to learn how the API on that system works and then create the code to use it.

Some API's can be tested with a browser. These allow for URL parameters to be sent and the data will be returned.

The best thing to do is find the specific API your interested in working on. Then look at the documentation.

Try creating an interface to work with it. When you have problems then post your questions.


All times are GMT -6. The time now is 08:04 AM.