Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding some more methods and fixing some minor issues

  • Loading branch information...
commit de5eb9bd83b4455017c67c73aef59113080fdc8f 1 parent 890d939
@Lazyshot authored
Showing with 67 additions and 17 deletions.
  1. +21 −13 README.md
  2. +46 −4 lib/FacebookAds.js
View
34 README.md
@@ -15,19 +15,24 @@
console.log(stats);
});
- fb.createAdGroup({
- name: "Test Group Name",
- creative: {
- type: 9,
- object_id: 125772667501234
- },
- max_bid: 30,
- bid_type: 1,
- targeting: {
- countries: ['US']
- }
- }, function(adgroup) {
- console.log(adgroup);
+ fb.getAdCampaigns(function(campaigns){
+ campaign_id = campaigns.data[0].id;
+
+ fb.createAdGroup({
+ campaign_id: campaign_id,
+ name: "Test Group Name",
+ creative: {
+ type: 9,
+ object_id: 125772667501234
+ },
+ max_bid: 30,
+ bid_type: 1,
+ targeting: {
+ countries: ['US']
+ }
+ }, function(adgroup) {
+ console.log(adgroup);
+ });
});
## Methods
@@ -36,6 +41,9 @@
* createAdCampaign(settings, cb)
* createAdGroup(settings, cb)
* createAdCreative(settings, cb)
+* getAdCampaigns(cb)
+* getAdGroups([account_id,] cb)
+* getAdCreatives(cb)
* getAdCampaignStats(campaign_id, cb)
* getAdGroupStats(adGroupId, cb)
* getAdAccountStats([accountId,] cb)
View
50 lib/FacebookAds.js
@@ -47,6 +47,42 @@ FacebookAds.prototype = {
);
},
+ getAdGroups: function(campaign_id, cb) {
+ var url = "";
+
+ if(typeof(campaign_id) == "function")
+ {
+ url = "/act_" + this.config.accountId + "/adgroups";
+ cb = campaign_id;
+ } else {
+ url = "/" + campaign_id + "/adgroups";
+ }
+
+ this.makeRequest(
+ url,
+ {},
+ cb
+ );
+ },
+
+
+ getAdCampaigns: function(cb) {
+ this.makeRequest(
+ "/act_" + this.config.accountId + "/adcampaigns",
+ {},
+ cb
+ );
+ },
+
+ getAdCreatives: function(cb) {
+ this.makeRequest(
+ "/act_" + this.config.accountId + "/adcreatives",
+ {},
+ cb
+ );
+ },
+
+
getAdsStats: function(objectId, params, cb) {
this.makeRequest(
@@ -56,7 +92,6 @@ FacebookAds.prototype = {
);
},
-
getAdGroupStats: function(adGroupId, params, cb) {
this.getAdsStats(adGroupId, params, cb);
},
@@ -67,13 +102,13 @@ FacebookAds.prototype = {
getAdAccountStats: function(adAccountId, cb) {
- if(typeof(adAcc) == "function")
+ if(typeof(adAccountId) == "function")
{
cb = adAccountId;
adAccountId = this.config.accountId;
}
- this.getAdsStats(adAccountId, {}, cb);
+ this.getAdsStats("act_" + adAccountId, {}, cb);
},
makeRequest: function(url, params, callback, method) {
@@ -109,7 +144,14 @@ FacebookAds.prototype = {
fulldata += d;
});
res.on('end', function(){
- callback(JSON.parse(fulldata));
+ var data = JSON.parse(fulldata);
+
+ if('error' in data)
+ {
+ throw new Error("Type: " + data.error.type + " Message: " + data.error.message);
+ }
+
+ callback(data);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.