Google Affiliate Network API PHP Script

Google Affiliate Network

I was excited when I read Google had released an API for their Affiliate Network, as I wanted to automate pulling sales data from GAN. But I quickly became disheartened when I realized how difficult it is to use.

Since this was for myself, and not a web-based service that would be used by others, the Simple API method of authorization was good enough. After getting it to work with Picasa, but not GAN, I asked for some help and was introduced to the OAuth 2.0 Playground. This showed me the headers I’d need to send, and how OAuth 2.0 works.

For the record: the Google Affiliate Network API does NOT support Simple API Access. You cannot access the service with an API Key and IP locking.

I now have a working script, and have written up step-by-step instructions on how you can pull orders from GAN automatically each day.

This script is not complete, as it’s up to you to do something with the data once you have it. You can also modify the final call to pull advertisers, instead of orders.

How To & Tips



Scraping Websites using PHP’s Document Object Model

ScraperI had a need to get some data that wasn’t available in the merchant’s datafeed, and since I wasn’t going to be putting a huge burden on the merchant’s site (ie: if you scrape, be nice*) I decided to write a little scraper to do so.

In this script, I’m using all, pure PHP functions: cURL, Document Object Model, SimpleXML. By using PHP’s built-in functions, the script will be as portable and efficient as possible.

How To & Tips


How To Specify The Thumbnail Image When Sharing A Link On Facebook From Your Thesis Site

Thesis ThemeAt the time of writing this, Facebook’s Like (or Share) button acts the same as sharing or posting a URL to your wall, except you don’t have the chance to leave a comment or choose which image to include with the post.

If you post a link to your wall, Facebook will guess at which images on the page may be best suitable for the page, and allow you to choose from several of them

How To & Tips


Using the Microsoft adCenter API to Automate Reporting in PHP

Microsoft Advertising LogoAfter nearly three months of on & off coding, banging my head against the table and thumbing through the most comprehensive yet incomprehensible documentation I’ve ever seen, I was finally able to automate downloading stats (impressions, clicks, cost) for my coupon site.

For the longest time, the adCenter API was very closed. However, it now seems they’re opening it up, and I quickly was able to get an API account, but wasn’t able to get anything to work. Even adCenter’s most simple script doesn’t work out of the box, and it’s nearly impossible to figure out what has to be done. Hopefully this post will help you.

How To & Tips




Using the LinkShare Merchandiser Web Service

Linkshare Web Services

Linkshare Web Services

Building a product site using the LinkShare Merchandiser Web Service is one of the easiest and most straight-forward tasks you can do. If you’re just getting started with datafeeds and product-based sites, you may want to start here.

If you don’t have an account, you first need to signup with LinkShare. Then login, and click on Web Services under Links. Next, generate or update your token. You’ll need this when making requests.



Tracking CJ Commissions with Prosper202

CJ + Prosper202 logosI got a call today from a guy in NJ looking to track CJ sales with Prosper202. He saw my post on Tracking ShareASale Commissions with Prosper202 and another post on using the Commission Junction Web Services and wanted some info on how to combine the two.

It’s actually pretty simple… just take the code from the CJ page, then the part where 202 is pinged from the SAS+202 post, and you get:

	$cDevKey = 'your-developer-key';

	$cURL = '';
	$cURL .= 'date-type=event&';

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $cURL);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
				  'Authorization: ' . $cDevKey,
				  'User-Agent: "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/2009101601 Firefox/3.0.15 GTB6 (.NET CLR 3.5.30729)"'

	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
	curl_setopt($ch, CURLOPT_TIMEOUT, 10);

	$cHTML = curl_exec($ch);
	if (curl_error($ch)) {
		echo "Curl error: " . curl_error($ch);
	} // ends if (curl_error($ch))
	else {
		$cXML = simplexml_load_string($cHTML);

		for ($i = 0; $i < count($cXML->commissions->commission); $i++) {
			$oCJCommission = $cXML->commissions->commission[$i];

			$cPostback = '' . urlencode($oCJCommission->{'commission-amount'}) . '&subid=' . urlencode($oCJCommission->sid);
			$fpPostback = @fopen($cPostback, "r");
			if ($fpPostback !== false) {
			} // ends if ($fpPostback !== false)
		} // ends for ($i = 0; $i < count($cXML->commissions->commission); $i++)
	} // ends else from if (curl_error($ch))

Cron this script (I have mine run every day about 7am) and you’ll see your CJ commissions in Prosper202

How To & Tips