Adblock breaks this site

API Integration: PHP

Discussion in 'Web Programming' started by Nick, Apr 14, 2012.

  1. Nick

    Nick ♬♩ Young Forever ♪ ♫

    Joined:
    Feb 12, 2007
    Posts:
    7,204
    Referrals:
    40
    Sythe Gold:
    80
    API Integration: PHP

    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
     
  2. iJava

    iJava .Previously known as RSGoldRush
    $200 USD Donor New

    Joined:
    Nov 21, 2011
    Posts:
    1,197
    Referrals:
    11
    Sythe Gold:
    485
    Discord Unique ID:
    220055593568829441
    API Integration: PHP

  3. Deacon Frost

    Deacon Frost Grand Master
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57
    API Integration: PHP

    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.
     
  4. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    API Integration: PHP

    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());
    }
    
     
< Need some HTML explaining | Which to learn first? >


 
 
Adblock breaks this site