PHP code example of swco / appnexusapi

1. Go to this page and download the library: Download swco/appnexusapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swco / appnexusapi example snippets


use \SWCO\AppNexusAPI\Request;

$request = new Request("username", "password");

// Get category ID 1 and 7
$categories = $request->whereId(array(1, 7))->getCategories();

// Get category ID 5
$category = $request->getCategory(5);

// Get all brands update since June 2014
$brands = $request->get(Request::SERVICE_BRAND)->since(new DateTime('June 2014'))->send();
echo $brands->getStatus();// OK

// Domain Audit Statuses are a bit different as they needs some post data
$domainAuditStatus = $request->getDomainAuditStatuses(array('google.com'));

use \SWCO\AppNexusAPI\Request;
use \SWCO\AppNexusAPI\BrandRequest;

$request = new Request("username", "password");

$brand = BrandRequest::newFromRequest($request);

$brand->simple();

...

use \SWCO\AppNexusAPI\Request;
use \SWCO\AppNexusAPI\BrandRequest;

$request = new Request("username", "password");

$brand = BrandRequest::newFromRequest($request);

$simple = true;
$brand->getBrand(1, $simple);

use \SWCO\AppNexusAPI\Request;

$request = new Request("username", "password");
$token = $request->auth();

// Store $token somewhere

use \SWCO\AppNexusAPI\Auth;
use \Guzzle\Http\Client;
use \SWCO\AppNexusAPI\Request;
use \SWCO\AppNexusAPI\Exceptions\NoAuthException;

$auth = new Auth();
$auth->setClient(new Client(Request::APP_NEXUS_API_URL));
try {
    $token = $auth->auth('username', 'password');
} catch (NoAuthException $e) {
    $token = null;
}

if ($token) {
    // Store $token somewhere
}

use SWCO\AppNexusAPI\DataPool;
use SWCO\AppNexusAPI\Request;

$request = new Request('username', 'password');
$request->get(Request::SERVICE_DEVICE_MAKE);

$dataPool = new DataPool();

$data = $dataPool->getAll($request); // Gets all Device Make items

$data = $dataPool->get($request, 250); // Gets the first 250 results of the Device Make items.

$request->offsetBy(250);

$data = $dataPool->get($request, 250); // Gets items 250 - 500.