Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Location
    Narrich
    Posts
    5,687
    Tokens
    0
    Habbo
    Jamesy...

    Latest Awards:

    Default vBulletin 4.1 Mobile API

    Anyone had a play on this yet? It's been distracting me for a few days learning it now that the documentation has been released.

    I've managed to whip this up. Probably not the most elegant code but it works for testing things:
    PHP Code:
        // Api Key - generated from: admincp/api.php
        
    $Apikey = "";

        
    // Insert the parameters to build the API on: http://www.vbulletin.com/forum/content.php?366-REST-Server-Specific-Methods
        
    $Api_InitParams = array("clientname" => 'apitest', "clientversion" => '1', "platformname" => 'PHP', "platformversion" => '5', "uniqueid" => $Apikey);
        
    ksort($Api_InitParams);
        
    $Api_InitParams = http_build_query($Api_InitParams, '', '&');

        
    $Api_Url = "http://localhost/api.php?api_m=api_init&{$Api_InitParams}";
        
    $vBInfo= json_decode(file_get_contents($Api_Url), true);

        
    // Build Common Array
        
    $ApiParamsArray = array("api_c" => $vBInfo['apiclientid'], "api_s" => $vBInfo['apiaccesstoken'], "api_v" => $vBInfo['apiversion']);
        
    ksort($ApiParamsArray);
        
    $ApiParams = http_build_query($ApiParamsArray, '', '&'); 
    So to get user data for example, include the above and:
    PHP Code:
        // Include the API Data
        
    require_once("api_init.php");

        
    // Get Member info into an array and format for Sign
        
    $UserParamsArray = array("api_m" => "member", "username" => $_GET['username']);
        
    $UserParams = http_build_query($UserParamsArray, '', '&');
        
        
    // Format full URL Structure
        
    $UserUrlStructure = array_merge($UserParamsArray, $ApiParamsArray);
        
    ksort($UserUrlStructure);
        
    $UserUrlStructure = http_build_query($UserUrlStructure, '', '&');
        
        
    //Generate the API Sign
        
    $Sign = md5($UserParams.$vBInfo['apiaccesstoken'].$vBInfo['apiclientid'].$vBInfo['secret'] . $Apikey);
        
        
    //Generate the URL String
        
    $UserUrl = $vBInfo['bburl'] . "api.php?" . $UserUrlStructure . "&api_sig=" . $Sign;
        
    // Get the Data
        
    $UserData = json_decode(file_get_contents($UserUrl), 1); 
    You're supposed to check the sign on the response but I've forgotten to do that. I got confused by how to sign the api calls at first, it's essentially this:
    PHP Code:
    $Sign = md5($UserParams.$vBInfo['apiaccesstoken'].$vBInfo['apiclientid'].$vBInfo['secret'] . $Apikey); 
    I've not really played much more than basic things that could be done without using the API, it's still fun to learn though .
    Ex-janitor. Might pop in from time to time, otherwise you can grab all my information from http://jamesy.me.uk/

  2. #2
    Join Date
    Jun 2005
    Posts
    2,850
    Tokens
    3,979
    Habbo
    Skynus

    Latest Awards:

    Default

    I've not really checked it out. Nice coding btw I'll check it out soon, maybe drift away like you did for a while

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •