Coder Social home page Coder Social logo

facebook-js-ads-sdk's Introduction

Facebook Ads API SDK for JS Build Status

A Promise-based SDK built to facilitate application development for Facebook Ads API.

Installation

The SDK is is served as a UMD module that works in Node, AMD (RequireJS) and as a browser global variable.

Client side

Load api.js through RequireJS or add the SDK scripts into you HTML to run as a global variable.

The SDK requires a Promises/A spec implementation. These are currently supported in most modern browsers.

Server side

The Facebook Ads API SDK requires Node.js v 0.12 or greater for server side environment. Facebook Ads API SDK uses NPM to manage dependencies which comes bundled with Node. You can follow this document to install Node.js.

Install dependencies running:

npm install

Usage

To instantiate an Api object you will need a valid access token:

var api = new FacebookAdsApi(token);

Facebook Objects

Facebook Object constructors are present in the Api object an can instantiate new objcts using it's ID as an argument:

var myAdAccount = new api.AdAccount('act_XXXXXXXXXXXXXXX');

New objects can also be instantiated with a data object to be saved:

var myNewCampaign = new api.AdCampaign({name: 'My new campaign'}, 'act_XXXXXXXXXXXXXXX');

The object's fields can be accessed and modified as a normal JS object properties:

myNewCampaign.name; // "My new campaign"

CRUD operations

Most of Facebook's Objects can perform Create, Read, Update, and Delete operations. These operations return Promises wich once resolved can alter the object's data or return the operation's success status:

Create
myNewCampaign.create()
  .then(function() {
    myNewCampaign.id; // "12334567890"
  };
Read
var adCampaign = new api.AdCampaign('12334567890');
adCampaign.read()
  .then(function() {
    adCampaign.name; // "My new campaign"
  };
Update
adCampaign.name = 'Campaign new name';
adCampaign.update()
  .then(function(data) {
    data.success; // true
  };
Delete
adCampaign.delete()
  .then(function(data) {
    data.success; // true
  };

Tests

The test folder contains the unit test cases. The live folder contains tests that run against the real Facebook Api, effectively creating the Objects and deleting them afterwards (use these at your own discretion).

Install dependencies

The client side unit tests are run in the browser. To install the dev dependencies for tests run:

bower install

The server side and live tests are run with gulp, which is installed among the depencencies running

npm install

Configure tests

1 - Copy the config file template. cp test/test-data.sample.js test/test-data.js 2 - Edit test/test-data.js with your information.

Run tests

You can access /test/index.html in your browser for tests using the RequireJS loader or /test/global.html to run the global variable version.

The default gulp task will run will watch the files and run 'jscs', 'jshint' and 'test' tasks in the server.

The gulp live task will startup a testing server where you can grab a Token and run the live tests.

To run tests individually: gulp test

facebook-js-ads-sdk's People

Contributors

lucasrcosta avatar foglio avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.