Skip to content
Ryan Hertz edited this page Dec 6, 2016 · 4 revisions

Create a file in the project root called cli.php and add this. Be sure to update my_api_key and my_api_secret.

<?php

header('Content-Type: text/html; charset=UTF-8');

// include the SparkAPI core which autoloads other classes as necessary
require_once("lib/Core.php");

$api = new SparkAPI_APIAuth("my_api_key", "my_api_secret");

$api->SetApplicationName("PHP-CLI-Example");

$api->api_base = "sparkapi.com";

// authenticate
$result = $api->Authenticate();
if ($result === false) {
    echo "API Error Code: {$api->last_error_code}<br>\n";
    echo "API Error Message: {$api->last_error_mess}<br>\n";
    exit;
}

Then launch php in interactive mode and load this file.

$ php -a -d auto_prepend_file=cli.php

You can now call any of the functions defined in lib/Core.php on $api.

php > $api->GetListings();
Clone this wiki locally