-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial checkin of autogenerated Node JS SDK for Marketing APIs. Here…
… are the list of features that this Node JS SDK includes, - CRUD Operations on all Nodes and Edges - Compilation into script bundles - Type safety (Flow) - File upload - Video upload utility - Batch API functionality
- Loading branch information
0 parents
commit 86d7ce2
Showing
158 changed files
with
10,571 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# distribution packages | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
test/**/suite.js* | ||
test/**/*.json | ||
node_modules | ||
bower_components | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Contributing to Facebook Ads API SDK for NodeJS | ||
We want to make contributing to this project as easy and transparent as | ||
possible. | ||
|
||
## Our Development Process | ||
The Facebook Ads API SDK for NodeJS is currently developed in Facebook's internal | ||
repositories and then exported out to GitHub by a Facebook team member. We invite | ||
you to submit pull requests directly to GitHub and, after review, these can be | ||
merged into the project. | ||
|
||
## Pull Requests | ||
We actively welcome your pull requests. | ||
|
||
1. Fork the repo and create your branch from `master`. | ||
2. If you've added code that should be tested, add tests. | ||
3. If you've changed APIs, update the documentation. | ||
4. Ensure the test suite passes. | ||
5. Make sure your code lints. | ||
6. If you haven't already, complete the Contributor License Agreement ("CLA"). | ||
|
||
## Contributor License Agreement ("CLA") | ||
In order to accept your pull request, we need you to submit a CLA. You only need | ||
to do this once to work on any of Facebook's open source projects. | ||
|
||
Complete your CLA [here](https://code.facebook.com/cla) | ||
|
||
## Issues | ||
We use GitHub issues to track public bugs. Please ensure your description is | ||
clear and has sufficient instructions to be able to reproduce the issue. | ||
|
||
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe | ||
disclosure of security bugs. In those cases, please go through the process | ||
outlined on that page and do not file a public issue. | ||
|
||
## Coding Style | ||
Please follow [The Flow Standard](https://github.com/Flet/semistandard) | ||
|
||
## License | ||
By contributing to Facebook Ads API SDK for NodeJS, you agree that your contributions | ||
will be licensed under the LICENSE file in the root directory of this source tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Copyright (c) 2017-present, Facebook, Inc. All rights reserved. | ||
|
||
You are hereby granted a non-exclusive, worldwide, royalty-free license to use, | ||
copy, modify, and distribute this software in source code or binary form for use | ||
in connection with the web services and APIs provided by Facebook. | ||
|
||
As with any software that integrates with the Facebook platform, your use of | ||
this software is subject to the Facebook Platform Policy | ||
[http://developers.facebook.com/policy/]. This copyright notice shall be | ||
included in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
# Facebook Ads API SDK for NodeJS | ||
|
||
[![License](https://img.shields.io/badge/license-Facebook%20Platform-blue.svg?style=flat-square)](https://github.com/facebook/facebook-nodejs-ads-sdk/blob/master/LICENSE) | ||
|
||
This Ads API SDK is built to facilitate application development for [Facebook Ads API](https://developers.facebook.com/docs/ads-api). | ||
This SDK can be used for both server side as well as client side. It comes with ECMAScript 5 bundled minified distribution with source maps of AMD, CommonJS modules, IIFE, as UMD and as Browser Globals. | ||
|
||
### Dependencies | ||
|
||
[Gulp](http://gulpjs.com/) and [Bower](http://bower.io/) should be installed globally. Install depencencies: | ||
|
||
``` bash | ||
npm install | ||
bower install | ||
``` | ||
|
||
Checkout `gulpfile.js` for all available tasks. | ||
|
||
|
||
## Installation | ||
|
||
NPM | ||
|
||
npm install --save facebook-nodejs-ads-sdk | ||
|
||
Bower | ||
|
||
bower install --save facebook-nodejs-ads-sdk | ||
|
||
## Usage | ||
|
||
### Access Token | ||
|
||
To instantiate an Api object you will need a valid [access token](https://developers.facebook.com/docs/marketing-api/authentication) for an app with the `ads_management` permission. A quick way to obtaining a short-lived token is using the [Graph API Explorer](https://developers.facebook.com/tools/explorer/). Instantiate the API using the token: | ||
|
||
```javaScript | ||
const FacebookAdsApi = require('facebook-nodejs-ads-sdk').FacebookAdsApi; | ||
const api = FacebookAdsApi.init(accessToken) | ||
``` | ||
|
||
### Api main class | ||
|
||
The `FacebookAdsApi` object is the foundation of the Ads SDK which encapsulates the logic to execute requests against the Graph API. | ||
|
||
To instantiate an Api object you will need a valid access token: | ||
```javaScript | ||
const adsSdk = require('facebook-nodejs-ads-sdk'); | ||
const accessToken = '<VALID_ACCESS_TOKEN>'; | ||
const accountId = '<AD_ACCOUNT_ID>'; | ||
|
||
const FacebookAdsApi = adsSdk.FacebookAdsApi.init(accessToken); | ||
``` | ||
|
||
Once instantiated, the Api object will allow you to start making requests to the Ads API. | ||
|
||
### Facebook Objects | ||
|
||
Facebook Ads entities are defined as classes under the `src/objects` directory. | ||
|
||
```javascript | ||
// instantiating an object | ||
const AdAccount = require('facebook-nodejs-ads-sdk').AdAccount; | ||
const account = new AdAccount(accountId); | ||
console.log(account.id) // fields can be accessed as properties | ||
``` | ||
|
||
### Fields | ||
|
||
Due to the high number of field names in the Ads API existing objects, in order to facilitate your code maintainability, enum-like field objects are provided within each node class. | ||
The fields are stored within node object classes which are stored under the `src/objects` directory. | ||
You can access object properties like this, | ||
|
||
```javaScript | ||
const adsSdk = require('facebook-nodejs-ads-sdk'); | ||
const AdAccount = adsSdk.AdAccount; | ||
const Campaign = adsSdk.Campaign; | ||
const account = new AdAccount('<AD_ACCOUNT_ID>'); | ||
|
||
console.log(account.id) // fields can be accessed as properties | ||
account | ||
.createCampaign( | ||
[Campaign.Fields.Id], | ||
{ | ||
[Campaign.Fields.name]: 'Page likes campaign', // Each object contains a fields map with a list of fields supported on that object. | ||
[Campaign.Fields.status]: Campaign.Status.paused, | ||
[Campaign.Fields.objective]: Campaign.Objective.page_likes | ||
} | ||
) | ||
.then((result) => { | ||
}) | ||
.catch((error) => { | ||
}); | ||
``` | ||
|
||
#### Read Objects | ||
|
||
```javascript | ||
const adsSdk = require('facebook-nodejs-ads-sdk'); | ||
const AdAccount = adsSdk.AdAccount; | ||
const account = new AdAccount('<AD_ACCOUNT_ID>'); | ||
account | ||
.read([AdAccount.Fields.name, AdAccount.Fields.age]) | ||
.then((account) => { | ||
logPassedTest(test1 + ':Pass', account); | ||
}) | ||
.catch((error) => { | ||
}); | ||
``` | ||
|
||
Requesting an high number of fields may cause the response time to visibly increase, you should always request only the fields you really need. | ||
|
||
#### Create Objects | ||
|
||
```javascript | ||
const adsSdk = require('facebook-nodejs-ads-sdk'); | ||
const AdAccount = adsSdk.AdAccount; | ||
const Campaign = adsSdk.Campaign; | ||
const account = new AdAccount('<AD_ACCOUNT_ID>'); | ||
account | ||
.createCampaign( | ||
[], | ||
{ | ||
[Campaign.Fields.name]: 'Page likes campaign', | ||
[Campaign.Fields.status]: Campaign.Status.paused, | ||
[Campaign.Fields.objective]: Campaign.Objective.page_likes | ||
} | ||
) | ||
.then((campaign) => { | ||
}) | ||
.catch((error) => { | ||
}); | ||
``` | ||
|
||
#### Update Objects | ||
|
||
```javascript | ||
const Campaign = require('facebook-nodejs-ads-sdk').Campaign; | ||
const campaignId = <CAMPAIGN_ID>; | ||
new Campaign(campaignId, { | ||
[Campaign.Fields.id]: campaign.id, | ||
[Campaign.Fields.name]: 'Campaign - Updated' }) | ||
.update(); | ||
``` | ||
|
||
#### Delete Objects | ||
|
||
```javascript | ||
const Campaign = require('facebook-nodejs-ads-sdk').Campaign; | ||
const campaignId = <CAMPAIGN_ID>; | ||
new Campaign(campaignId); | ||
.delete(); | ||
``` | ||
|
||
### Pagination | ||
|
||
Since the release of the Facebook Graph API 2.0, pagination is handled through [cursors](https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging). | ||
Here cursors are defined as in `src\cursor.js`. When fetching nodes related to another (Edges) or a collection in the graph, the results are paginated in a `Cursor` class. | ||
Here the `Cursor` is a superpowered `Array` (with all it's native helpful operations) with `next` and `previous` methods that when resolved fills itself with the new set of objects. | ||
|
||
```javascript | ||
const adsSdk = require('facebook-nodejs-ads-sdk'); | ||
const AdAccount = adsSdk.AdAccount; | ||
const Campaign = adsSdk.Campaign; | ||
const account = new AdAccount('<AD_ACCOUNT_ID>'); | ||
account.getCampaigns([Campaign.Fields.name], { limit: 2 }) | ||
.then((campaigns) => { | ||
if (campaigns.length >= 2 && campaigns.hasNext()) { | ||
return campaigns.next(); | ||
} else { | ||
Promise.reject( | ||
new Error('campaigns length < 2 or not enough campaigns') | ||
); | ||
} | ||
}) | ||
.then((campaigns) => { | ||
if (campaigns.hasNext() && campaigns.hasPrevious()) { | ||
return campaigns.previous(); | ||
} else { | ||
Promise.reject( | ||
new Error('previous or next is not true') | ||
); | ||
} | ||
return campaigns.previous(); | ||
}) | ||
.catch((error) => { | ||
}); | ||
``` | ||
|
||
#### Debugging | ||
|
||
A `FacebookAdsApi` object offers a debugging mode that will log all requests. To enable it just call `api.setDebug(true)` on an API instance. | ||
|
||
|
||
### Style | ||
|
||
This package uses type safe javascript. [Flow](https://flow.org/). Inconsistent code will break builds. | ||
|
||
## Join the Facebook Marketing Developer community | ||
* Website: https://www.facebook.com/groups/pmdcommunity | ||
* Facebook page: https://www.facebook.com/marketingdevelopers/ | ||
See the CONTRIBUTING file for how to help out. | ||
|
||
## License | ||
Facebook Ads API SDK for NodeJS is licensed under the LICENSE file in the root directory of this source tree. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "facebook-ads-sdk", | ||
"version": "2.9.0", | ||
"description": "SDK for the Facebook Ads API in Javascript and Node.js", | ||
"authors": [ | ||
"Zain Aziz<[email protected]>", | ||
"Neil Chen <[email protected]>", | ||
"Cloud Xu <[email protected]>", | ||
"Supasate Choochaisri <[email protected]>" | ||
], | ||
"homepage": "https://github.com/facebook/facebook-nodejs-ads-sdk/", | ||
"bugs": "https://github.com/facebook/facebook-nodejs-ads-sdk/issues", | ||
"keywords": [ | ||
"facebook", | ||
"ads", | ||
"sdk", | ||
"api", | ||
"javascript", | ||
"nodejs", | ||
"amd", | ||
"requirejs", | ||
"umd", | ||
"promises" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/facebook/facebook-nodejs-ads-sdk.git" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "~6.17.0", | ||
"babel-plugin-external-helpers": "~6.8.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-flow": "^6.23.0", | ||
"babel-preset-stage-2": "^6.24.1", | ||
"babelrc-rollup": "^3.0.0", | ||
"chai": "~3.5.0" | ||
}, | ||
"main": "./dist/iife.js", | ||
"license": "Platform License" | ||
} |
Oops, something went wrong.