Help Center > Manage Your Account > AdSpeed API

Sample Code

Please see the example below to access AdSpeed API.

PHP

<?php
class MyApp {
	private $mEndPoint = 'http://api.adspeed.com/';
	private $mKey = 'YOUR_KEY'; // change to your own key
	private $mSecret = 'YOUR_SECRET'; // change to your own secret

	/**
	* Request API method via GET
	* @param string method
	* @param array params
	* @return string
	*/
	public function getAPI($pMethod,$pParams=array()) {
		$vParams = array('key'=>$this->mKey,'method'=>$pMethod);
		$vParams = array_merge($pParams,$vParams);
		ksort($vParams); // sort the params alphabetically
		$vParams['md5'] = md5($this->mSecret.http_build_query($vParams,'','&'));
		$vURL = $this->mEndPoint.'?'.http_build_query($vParams,'','&');
		
		$vCURL = curl_init($vURL);
		curl_setopt($vCURL,CURLOPT_RETURNTRANSFER,1); // get XML result as string
		$vResult = curl_exec($vCURL);
		curl_close($vCURL);
		return $vResult;
	}

	/**
	* Request API method via POST
	* @param string method
	* @param array params
	* @return string
	*/
	public function postAPI($pMethod,$pParams=array()) {
		$vParams = array('key'=>$this->mKey,'method'=>$pMethod);
		$vParams = array_merge($pParams,$vParams);
		ksort($vParams); // sort the params alphabetically
		$vParams['md5'] = md5($this->mSecret.http_build_query($vParams,'','&'));
		
		$vCURL = curl_init($this->mEndPoint);
		curl_setopt($vCURL,CURLOPT_POST,1); // use POST instead of GET
		curl_setopt($vCURL,CURLOPT_POSTFIELDS,$vParams);
		curl_setopt($vCURL,CURLOPT_RETURNTRANSFER,1); // get XML result as string
		$vResult = curl_exec($vCURL);
		curl_close($vCURL);
		return $vResult;
	}
	
	/**
	* Sample usage
	* @return void
	*/
	public function example() {
		// GET		
		$vResult = $this->getAPI('AS.Ads.getCounts');
		var_dump($vResult);
		
		// POST
		$vParams = array(
			'name'=>'TextAdViaAPI',
			'first'=>'First Text Line',
			'next'=>'Second Line',
			'clickurl'=>'http://example.com',
		);
		$vResult = $this->postAPI('AS.Ads.createText',$vParams);
		var_dump($vResult);
	}
}

$vTest = new MyApp();
$vTest->example();

?>

Token Hash Generation

In certain methods that deal directly with one or more entities, a "token" parameter is required to verify ownership. The hash is generated by concatenating all the required fields into a single string and generating the MD5 hash for that string. Here is an example to generate token with format [Ad ID][Ad Name][Zone ID][Zone Name]:
Ad ID = '1234'
Ad Name = 'MyTestAd'
Zone ID = '789' 
Zone Name = 'MyTestZone'

token = md5('1234MyTestAd789MyTestZone') 
token = '971b6ebe7580f203905a0bf3fde9fd7b'

Other Articles in AdSpeed API

Documentation about building applications with AdSpeed API
Search Help Center
There was a problem with your submission. Please correct the following items:

    Cannot find an answer for your question? Ask our Customer Care team

    Related Articles

    • AdSpeed API Overview i
      "AdSpeed API (Application Programming Interface) is an add-on service we provide to our clients. Publishers and advertisers can write software ..."
    • Ad i
      "Documentation for API methods to manage one or multiple ads. API Version1.2.7 (build 20110606). Documentation was last modified on Sun, ..."
    • Website i
      "Documentation for API methods to manage one or multiple websites. API Version1.2.7 (build 20110606). Documentation was last modified on Sun, ..."
    • Zone i
      "Documentation for API methods to manage one or multiple zones. API Version1.2.7 (build 20110606). Documentation was last modified on Sun, ..."

    Have questions? Contact Us

    Testimonials for our Ad Servers

    • I am extremely pleased with AdSpeed. Their technology has made our business shine with improved profits, mostly due to their unique ad server and amazing support. There is no other company I would even consider to compare to AdSpeed.

      Markus S.
      CEO, Dream Ware Enterprise

    • That was fast and works exactly right! Thanks again for your superb support!

      Dr Tom Bailey
      Aquarium Fish