PHP code example of bokbasen / php-sdk-met-api

1. Go to this page and download the library: Download bokbasen/php-sdk-met-api 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/ */

    

bokbasen / php-sdk-met-api example snippets



use Bokbasen\Auth\Login;
use Bokbasen\ApiClient\Client;

$auth = Login('username', 'password');
$client = new Client($auth);


use Bokbasen\Metadata\Export\Onix;
$onixClient = new Onix($client, Onix::URL_PROD, Onix::SUBSCRIPTION_EXTENDED);


$onixAsString = $onixClient->getByISBN('9788276749557');


$nextToken = $onixClient->downloadAfter(new \DateTime('2017-01-01'),'/onixFolder/');
//Save next token for later use


//Loop to get all pages
$morePages = true;
while($morePages){
	$morePages = $onixClient->downloadNext($nextToken,'/onixFolder/');
	$nextToken = $onixClient->getLastNextToken();
}

//Save next token for later use


$response = $onixClient->getAfter(new \DateTime('2017-01-01')); 
//Implement your own parsing here and get token from header

//Use token to get more pages
$response = $onixClient->getNext($token); 


$nextToken = $objectClient->downloadAfter(new \DateTime('2017-10-01'),'/pathForObjects/');
//Save next token for later use


//Loop to get all pages, each page will be stored as separate file
$morePages = true;
while($morePages){
	$morePages = $onixClient->downloadNext($nextToken,'/pathForObjects/');
	$nextToken = $onixClient->getLastNextToken();
}

//Save next token for later use


//Only download spesific types of objects
$nextToken = $objectClient->downloadAfter(new \DateTime('2017-10-01'),'/pathForObjects/',[\Bokbasen\Metadata\Export\Object::OBJECT_TYPE_AUDIO_SAMPLE,\Bokbasen\Metadata\Export\Object::OBJECT_COVER_IMAGE_SMALL]);

//you can also download for spesific ISBNs ($downloadAllPages must be true for this to work, and ensure to set a old date)
$objectClient->downloadAfter(new \DateTime('1950-01-01'),'/pathForObjects/',[\Bokbasen\Metadata\Export\Object::OBJECT_TYPE_AUDIO_SAMPLE,\Bokbasen\Metadata\Export\Object::OBJECT_COVER_IMAGE_SMALL],true,['9788251824491','9788215012520']);