Skip to content

Commit

Permalink
Merge pull request #23 from liorrozen/individual-tokens
Browse files Browse the repository at this point in the history
Individual tokens
  • Loading branch information
liorrozen authored Mar 11, 2018
2 parents 7daf845 + 775625f commit 0d5a9ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ var FacebookInsightStream = require( "facebook-insight-stream" );

var options = {
pastdays: "30",
node: "page",
node: "page" OR "post" OR "app",
token: "Replace with your facebook access token",
period: "day",
metrics: ["page_views"],
itemList: [{id: page_id, token: page_token}],
itemList: 'See comment below'
}

var pageStream = new FacebookInsightStream( options )
Expand All @@ -33,6 +33,18 @@ var pageStream = new FacebookInsightStream( options )
.on( "progress", console.log )
```

### Item list

The `itemList` parameter can have be passed in two forms:

1. An array of page ids. Eg: `["PAGE_ID1", "PAGE_ID2", "PAGE_ID3"]`.
This can be used when fetching nodes of type `post` or `app`.
2. An array of page objects including id and page access_tokens. Eg:
`[{id: "PAGE_ID1", token: "ABC"}, {id: "PAGE_ID2", token: "DEF"}]`
When an access_token is passed with each object - it is used for the requests
instead of the top level user token.
This can be used when fetching nodes of type `page`.

### FacebookInsightStream options:

* `pastdays` (string)#number of collected days from today e.g "30", disregard to fetch beginning of time
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ FacebookInsightStream.prototype._initItem = function ( item ) {
var title = 'FACEBOOK ' + options.node.toUpperCase();
console.log( new Date().toISOString(), title, url )

return FacebookInsightStream._apiCall(url)
return FacebookInsightStream.apiCall(url)
.bind( this )
.get( 1 )
.then( JSON.parse )
Expand Down Expand Up @@ -237,7 +237,7 @@ FacebookInsightStream.prototype._collect = function ( metrics, item, buffer, eve

console.log( new Date().toISOString(), title, url );

return FacebookInsightStream._apiCall(url)
return FacebookInsightStream.apiCall(url)
.get( 1 )
.then( JSON.parse )
.then( errorHandler.bind( null, options ) )
Expand Down Expand Up @@ -336,7 +336,7 @@ FacebookInsightStream.prototype.handleError = function ( error, retry ) {
* @param {String} url
* @returns {Promise}
*/
FacebookInsightStream._apiCall = function (url) {
FacebookInsightStream.apiCall = function (url) {
return request.getAsync( url )
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facebook-insight-stream",
"version": "2.0.0",
"version": "3.0.0",
"description": "Readable stream for reading facebook insights",
"main": "index.js",
"scripts": {
Expand All @@ -14,7 +14,7 @@
"facebook",
"insights"
],
"author": "Oshri Bienhaker",
"author": "Panoply Dev Team",
"license": "MIT",
"bugs": {
"url": "https://github.com/panoplyio/facebook-insight-stream/issues"
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe( 'Multiple access tokens', function () {
it( 'uses item token', function() {
let token = 'thetoken'
let calledUrl = null
sandbox.stub(FacebookInsightStream, '_apiCall').callsFake(url => {
sandbox.stub(FacebookInsightStream, 'apiCall').callsFake(url => {
calledUrl = url
return Promise.resolve([null,'{"data":{}}']);
})
Expand Down

0 comments on commit 0d5a9ca

Please sign in to comment.