Example: API call results

In the below example, we'll get keywords with the get/keywords_2/keywords/ method.

	<?php

	use TopvisorSDKV2 as TV;

	// replace "..." with a path to the autoload.php file if you use composer
	include(__DIR__.'/../../autoload.php');

	// write a path to SDK Topvisor, if you don't use composer
	//include_once('topvisor-sdk/src/V2/Fields.php');
	//include_once('topvisor-sdk/src/V2/Page.php');
	//include_once('topvisor-sdk/src/V2/Pen.php');
	//include_once('topvisor-sdk/src/V2/Session.php');

	$projectId = '%NN%'; // your project ID

	// creating a session
	$Session = new TVSession();

	// initiating a call
	$selectorKeywords = new TVPen($Session, 'get', 'keywords_2', 'keywords');

	// setting the project_id parameter
	$selectorKeywords->setData(['project_id' => $projectId]);

	// request to get a keyword id and name
	$selectorKeywords->setFields(['id', 'name']);

	// filter keywords with 1, 2 or 3 tags
	$selectorKeywords->setFilters([
	TVFields::genFilterData('tags', 'IN', [1,2,3])
	]);

	// sort keywords alphabetically
	$selectorKeywords->serOrders([
	TVFields::genOrderData('name', 'ASC')
	]);

	// get 1,000 keywords in one API call
	$selectorKeywords->setLimit(1000);

	do{
	// processing request (display results page)
	$page = $selectorKeywords->exec();

	// processing error
	if(is_null($page->getResult())) return var_dump($page->getErrors());

	// $page - array of keywords
	foreach($page->getResult() as $resultItem){
	echo $resultItem->id.': '.$resultItem->name.'<br>';
	}

	// find missing keywords
	// (if this is the last page, $nextOffset is equal to null)
	$nextOffset = $page->getNextOffset();
	if($nextOffset) $selectorKeywords->setOffset($nextOffset);

	// keep on retrieving keywords until all pages retrieved
	}while($nextOffset);