php facebook ads api

Update 24/11/2010: This is now being sold on it’s own site.

Sick of waiting for the facebook ads API? Download my PHP one today. Features include:

  • Create ads from PHP script loop. You can modify any paramaters you want and submit 100s of ads an hour but that will prob get your account banned
  • Pull info from your DB to submit ads. eg You could pull artist names and submit loads of ringtone ads using each individual artist
  • I provide a mysql table of all US cities you can target with Facebook, along with the user count for each city. So you can loop through all these and create targetted ads to every city in the US. eg ‘Meet Atlanta, GA Women’ today targetted at just Atlanta, GA demo. This is sure to improve CTR and lower your CPC.
  • Support for proxies

This is the code you use to create ads. #!/usr/local/bin/php
// The script doesn't support creating campaings yet so you need to get this from ads Manager. On the create an ad page, the select box at the bottom where you pick your campaign, just go into the HTML source and find the value for the campaign you want to use.
// Not sure if these 2 values make a difference. No harm in setting them right.

$query1=$mysql->query("SELECT * FROM us_cities WHERE done='no' ORDER BY usercount DESC");
while ($result1=$query1->fetch_assoc()) {
preg_match("/(.+?), .+?/",$city,$justcity);
// this uploads image used in ad.
// this actually creates and approves the ad. works like this createAd(ad name in ad manager, ad url without the http://, ad title (keep less than 25), ad body (keep less than 135), country, min age, max age, cpc bid, city id, gender targeted, education targeted) $JUSTCITY[1] has the name of just the city like Atlanta, $city has the state as well eg Atlanta, GA
$facebook->createAd($city,"{$insertid}","{$justcity[1]} Free Grants","Our records show 100s of unclaimed grants issued by Pres. Obama available to {$city} residents. You need to claim now.","US","21","25","0.39",$fbid,"male","all");
$query2=$mysql->query("UPDATE us_cities SET done='yes' WHERE id='{$insertid}' LIMIT 1");
// this is the value of seconds waited before submitting each ad. suggest keep it at 15 unless you want your account banned

Here’s a screenshot of the facebook cities table:Screenshot of phpMyAdmin

Price is $200$150. If you want a copy, paypal the cash to and I’ll email you a copy within a few hours.

Update 24/11/2010: This is now being sold on it’s own site.

Published by Georgie Casey

student. Google+

Join the Conversation


  1. is it possible to just get the stats from the FB ads account? like check how much money an ad spent today, etc?

Leave a comment

Your email address will not be published. Required fields are marked *