npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@achchiraj/facebook-api

v1.0.8

Published

simplify the interaction with facebook api graph

Downloads

14

Readme

@achchiraj/facebook-api

The facebook-api is a package designed to simplify interactions with the Facebook Graph API. It provides pre-defined packages for commonly used functionalities and enums for frequently used metrics and periods.

Installation

Install the package via npm:

npm install @achchiraj/facebook-api

Example of usage

const { FacebookPageApi } = require("@achchiraj/facebook-api");

// Call the userInfo method with the access token
const userInfos = await FacebookPageApi.userInfo(accessToken);
// Log the user information to the console
console.log(userInfos); // example result: { name: 'random name', email: '[email protected]' }

// Call the accountPages method with the access token and the fields needed
const facebookPages = await FacebookPageApi.accountPages(
  accessToken,
  "picture, name, access_token"
);
// Log the facebook pages
console.log(facebookPages); // example result: { picture: 'picture_url', name: 'page name', access_token: 'sadfrgsgsrgirugwfuacndncaoefoaiefoeufheufghs' }

Available Functions

Personal Account Functions :

exchangeToken(shortAccessToken: string, version?: string)

Exchange a short-lived access token for a long-lived one.

  • shortAccessToken: Short-lived access token to exchange.
  • version: version of the api (default: 'v20.0')
userInfo(accessToken: string, fields?: string, version?: string)

Fetch user information from Facebook.

  • accessToken: Access token of the user.
  • fields: Fields to retrieve (default: "name,picture").
  • version: version of the api (default: 'v20.0')
accountPages(access_token: string, fields?: string, version?: string)

Get information about the Facebook pages associated with the user.

  • access_token: Access token of the user.
  • fields: Fields to retrieve (default: "picture, category_list,category, tasks, name, access_token").
  • version: version of the api (default: 'v20.0')

Facebook Page Functions :

pageDetails(pageId: string, pageAccessToken: string, fields?: string)

Get page's details.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • fields: Fields to retrieve (default: "about,attire,bio,location,parking,hours,emails,website").
pageReviews(pageId: string, pageAccessToken: string) : Promise<IFbPageReviews[]>

Get page's reviews.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.

Object format:

[
  {
    created_time: string;
    recommendation_type: "positive" | "negative";
    review_text: string;
    reviewer: {
      name: string;
      id: string;
    };
  }
];
pagePosts(pageId: string, pageAccessToken: string, fields?: string, version?: string)

Get posts from a Facebook page.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • fields: Fields to retrieve (default: "full_picture,message,permalink_url,created_time,likes.summary(true),comments.summary(true),shares").
  • version: version of the api (default: 'v20.0')
pageLikes(pageId: string, pageAccessToken: string, version?: string)

Get the number of likes on a Facebook page.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • version: version of the api (default: 'v20.0')
pageAnalytics(pageId: string, pageAccessToken: string, date_preset?: PageInsightsDatePreset, period?: PageInsightsPeriod, version?: string)

Get analytics for a Facebook page.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • date_preset: Date preset for insights (default: PageInsightsDatePreset.this_year).
  • period: Period for insights (default: PageInsightsPeriod.month).
  • version: version of the api (default: 'v20.0')
pageWeeklyStats(pageId: string, pageAccessToken: string, date_preset?: PageInsightsDatePreset, period?: PageInsightsPeriod, metric?: string, version?: string)

Get weekly statistics for a Facebook page.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • date_preset: Date preset for insights (default: PageInsightsDatePreset.last_week_mon_sun).
  • period: Period for insights (default: PageInsightsPeriod.day).
  • metric: Metrics to retrieve (default: "page_post_engagements,page_impressions, page_daily_follows_unique").
  • version: version of the api (default: 'v20.0')

Facebook Page Posts Functions :

shareTextPostToPage(pageAccessToken: string, payload: ITextPostFbPayload, pageId: string, version?: string)

Share a text post to a Facebook page.

  • pageAccessToken: Access token of the page.
  • payload: Payload of the text post.
  • pageId: ID of the page to post to.
  • version: version of the api (default: 'v20.0')

Example:

const payload = {
  message: "Hello, world!",
  published: true,
  scheduled_publish_time: "2024-06-15T12:00:00Z",
};
sharePicturePostToPage(pageAccessToken: string, payload: IPicturePostFbPayload, pageId: string, version?: string)

Share a text post to a Facebook page.

  • pageAccessToken: Access token of the page.
  • payload: Payload of the picture post.
  • pageId: ID of the page to post to.
  • version: version of the api (default: 'v20.0')

Example:

const payload = {
  url: "picture_url",
  published: true,
  scheduled_publish_time: "2024-06-15T12:00:00Z",
};
updateTextPostOfPage(pageAccessToken: string, payload: { message: string }, pageId: string, version?: string)

Share a text post to a Facebook page.

  • pageAccessToken: Access token of the page.
  • payload: Payload of the picture post.
  • pageId: ID of the page to post to.
  • version: version of the api (default: 'v20.0')

Example:

const payload = {
  message: "picture_url",
};
pagePostsReactions(pageId: string, pageAccessToken: string, date_preset?: PageInsightsDatePreset period?: PageInsightsPeriod, metric?: string, version?: string)

Get reactions to posts on a Facebook page.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • date_preset: Date preset for insights (default: PageInsightsDatePreset.this_year).
  • period: Period for insights (default: PageInsightsPeriod.week).
  • metric: Metrics to retrieve (default: "page_actions_post_reactions_like_total, page_actions_post_reactions_love_total, page_actions_post_reactions_wow_total").
  • version: version of the api (default: 'v20.0')
pageScheduledPosts(pageId: string, pageAccessToken: string, fields?: string, version?: string)

Get scheduled posts from a Facebook page.

  • pageId: ID of the Facebook page.
  • pageAccessToken: Access token of the page.
  • fields: Fields to retrieve (default: "full_picture,message,permalink_url,created_time, likes.summary(true),comments.summary(true),shares").
  • version: version of the api (default: 'v20.0')
deleteFacebookPagePost(postId: string, pageAccessToken: string, version?: string)

Delete a post from a Facebook page.

  • postId: ID of the post to delete.
  • pageAccessToken: Access token of the page.
  • version: version of the api (default: 'v20.0')

Facebook Page Post Comments Functions :

pagePostComments(pagePostId: string, pageAccessToken: string, fields?: string, version?: string)

Get comments on a post from a Facebook page.

  • pagePostId: ID of the post.
  • pageAccessToken: Access token of the page.
  • fields: Fields to retrieve for comments (default: "from,message").
  • version: version of the api (default: 'v20.0')
commentOnPost(postId: string, pageAccessToken: string,comment: string, version?: string)

Delete a comment from a post on a Facebook page.

  • postId: ID of the post.
  • pageAccessToken: Access token of the page.
  • comment: The comment content.
  • version: version of the api (default: 'v20.0')
deleteComment(commentId: string, pageAccessToken: string, version?: string)

Delete a comment from a post on a Facebook page.

  • commentId: ID of the comment to delete.
  • pageAccessToken: Access token of the page.
  • version: version of the api (default: 'v20.0')
replyOnFacebookComment(commentId: string, pageAccessToken: string, reply: string, version?: string)

Reply to a comment on a post on a Facebook page.

  • commentId: ID of the comment to reply to.
  • pageAccessToken: Access token of the page.
  • reply: Reply message.
  • version: version of the api (default: 'v20.0')

Enums

PageInsightsDatePreset

An enum representing various date presets for Facebook page insights.

  • today: Today
  • yesterday: Yesterday
  • this_month: This month
  • last_month: Last month
  • this_quarter: This quarter
  • maximum: Maximum
  • data_maximum: Data maximum
  • last_3d: Last 3 days
  • last_7d: Last 7 days
  • last_14d: Last 14 days
  • last_28d: Last 28 days
  • last_30d: Last 30 days
  • last_90d: Last 90 days
  • last_week_mon_sun: Last week (Monday to Sunday)
  • last_week_sun_sat: Last week (Sunday to Saturday)
  • last_quarter: Last quarter
  • last_year: Last year
  • this_week_mon_today: This week (Monday to today)
  • this_week_sun_today: This week (Sunday to today)
  • this_year: This year

PageInsightsPeriod

An enum representing various periods for Facebook page insights.

  • day: Day
  • week: Week
  • days_28: 28 days
  • month: Month
  • lifetime: Lifetime
  • total_over_range: Total over range