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:
So to get user data for example, include the above and: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, '', '&');
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:
// 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);
I've not really played much more than basic things that could be done without using the API, it's still fun to learn thoughPHP Code:
$Sign = md5($UserParams.$vBInfo['apiaccesstoken'].$vBInfo['apiclientid'].$vBInfo['secret'] . $Apikey);
.