• Log in or sign up for an account here: https://www.sythe.org/login

API Integration: PHP

Nick

♬♩ Young Forever ♪ ♫

Do Not Trade
Joined
Feb 12, 2007
Sythe Gold
80
Messages
7,204
Location
United States
Can anyone explain the whole concept of how to do API integration on my website of another websites services? I know there are specific input vales necessary, the services API security key, etc but how does that translate to the actual code? Thanks if you're able to help

Nick
 

Lolwut?

Nick, explain what you mean? The concept is simple...

Let's take for instance you use Paypal's merchant gateway to accept automated payments. Additionally, you need to store the user's information locally so you can reference it for whatever reason.

Paypal gives you some different stuff you can use, or you can use a premade 'gateway' script that are available out there. There's some really good ones. During check out, you would send the user to the page with your post data, the post data would be entered to be sent to paypal. When paypal receives the post data, they return to you a confirmation as well as some basic other information. This is all automated, Paypal checks your post data, and then replies with more information.

You can then save the information in your database for reference.


APIs are very simple and straight forward. The other side has everything setup, all you have to do is send the right variables and know what variables you're getting back.
 
Surprised SOAP hasn't been mentioned.

It's commonplace in system to system communication. It allows for remote calling of PHP functions from a PHP script, instead of interpreting HTML results or requiring additional parsing of outputs.

Recommend reading http://shop.oreilly.com/product/9780596000950.do to learn how to use SOAP properly.

It's similar to a wget/fopen/cURL request, but with a few more features.
Code:
<?php
$soapClient = new SoapClient( NULL, array( 'location' => "http://yourwebsite.com/api.php", 'uri' => 'http://Otherwebsite.com' ) );

$params = array( 'ID'   => $ID,
                 'Key'  => $Key,
                 'More' => $more
               );
               
$return = $soapClient->__soapCall( 'functionName', $params );

if($return->statusCode() >= 200 && $return->statusCode() < 300 ) {
    // Something good was returned
    print_r($return->results());
}
 
Runescape Gamblingrunescape gambling
Back
Top