@geniucode/fb-graph-api
v1.0.3
Published
The purpose of this package is give most of the needed capabilities to work with Facebook graph API
Downloads
2
Readme
fb-graph-api
The purpose of this package is give most of the needed capabilities to work with Facebook graph API
Install
npm i --save @geniucode/fb-graph-api
Documentation
Prerequisites: Facebook App ID and App Secret
How to start?
import {init} from '@geniucode/fb-graph-api';
// in your root level
init('FB_APP_ID', 'FB_APP_SECRET');
How to set graph version?
import {setGraphVersion} from '@geniucode/fb-graph-api';
// pass the new version (e.g. 13.0)
setGraphVersion('13.0');
How to get graph version?
import {getGraphVersion} from '@geniucode/fb-graph-api';
const currentGraphVersion = getGraphVersion();
We can't do our work with short-lived token, so we need a long-lived one. How to extend the access token?
import {extendAccessToken} from '@geniucode/fb-graph-api';
const res = await extendAccessToken('appName', {
access_token: 'SHORT_ACCESS_TOKEN',
client_id: 'FB_APP_ID',
client_secret: 'FB_APP_SECRET'
});
const longLivedAccessToken = res.data.access_token;
---------QUERY--------- --For specific object--
import {queryOnUsers, queryOnPosts, queryOnPostComments} from '@geniucode/fb-graph-api';
// query on user data with query string
const userQueryRes = await queryOnUsers(
'appName',
'fields=likes,posts{message_tags,parent_id,shares}',
USER_ID,
LONG_ACCESS_TOKEN,
);
console.log({ userQueryResData: userQueryRes.data });
// query on user data with params
const userQueryRes2 = await queryOnUsers(
'appName',
{ fields: ['likes', 'posts{message_tags,parent_id,shares}'] },
USER_ID,
LONG_ACCESS_TOKEN,
);
console.log({ userQueryResData: userQueryRes2.data });
// query on post data with query string (total reactions count)
const postQueryRes = await queryOnPosts(
'appName',
'fields=reactions.summary(total_count)',
POST_ID,
LONG_ACCESS_TOKEN,
);
console.log({ postQueryResData: postQueryRes.data });
// query on post comments data with query string (total comments count)
const postCommentsQueryRes = await queryOnPostComments(
'appName',
'summary=1&filter=toplevel',
POST_ID,
LONG_ACCESS_TOKEN,
);
console.log({ postCommentsQueryResData: postCommentsQueryRes.data });
---------QUERY--------- -----Dynamic query-----
import {query} from '@geniucode/fb-graph-api';
const queryRes = await query('appName','me?fields=likes', LONG_ACCESS_TOKEN);
console.log({ queryResData: queryRes.data });
Contributors
- GeniuCode team