{"id":14384808,"url":"https://github.com/zaiste/facebookgraph","last_synced_at":"2025-06-10T14:04:15.510Z","repository":{"id":19837403,"uuid":"88046764","full_name":"zaiste/facebookgraph","owner":"zaiste","description":":globe_with_meridians: :two_men_holding_hands:   Node.js client for the Facebook Graph API with Flow","archived":false,"fork":false,"pushed_at":"2022-12-07T09:47:58.000Z","size":149,"stargazers_count":18,"open_issues_count":11,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-05T23:52:42.115Z","etag":null,"topics":["async","async-await","facebook","facebook-api","graph","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zaiste.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-12T11:59:32.000Z","updated_at":"2022-10-13T12:52:20.000Z","dependencies_parsed_at":"2023-01-13T20:37:24.783Z","dependency_job_id":null,"html_url":"https://github.com/zaiste/facebookgraph","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaiste%2Ffacebookgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaiste%2Ffacebookgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaiste%2Ffacebookgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaiste%2Ffacebookgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zaiste","download_url":"https://codeload.github.com/zaiste/facebookgraph/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaiste%2Ffacebookgraph/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259088479,"owners_count":22803642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-await","facebook","facebook-api","graph","nodejs"],"created_at":"2024-08-28T18:01:41.179Z","updated_at":"2025-06-10T14:04:15.448Z","avatar_url":"https://github.com/zaiste.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# facebookgraph \n\n![facebookgraph: Node.js client for the Facebook Graph API with Flow support](https://raw.githubusercontent.com/zaiste/facebookgraph/master/logo.png)\n\n`facebookgraph` is a Node.js client/interface for the [Facebook Graph API][3].\n\n* it uses [axios][1] instead of [requests][2]\n* it uses `async/await` syntax\n* it works only with Node.js 7.6+\n* it uses TypeScript\n* it comes with built-in pagination for fetching data from particular nodes or via search\n\n**Table of Contents**\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Request object using ID](#request-object-using-id)\n  - [Search API](#search-api)\n  - [Pagination](#pagination)\n  - [Posting text messages, photos or videos](#posting-text-messages-photos-or-videos)\n  - [Batch requests](#batch-requests)\n\n\n## Install\n\n```\nyarn add facebookgraph\n```\n\nor \n\n```\nnpm install facebookgraph\n```\n\n## Usage  \n\nIn order to use Facebook Graph API you need to have an access token which is being used to initialize `FacebookGraph` object. Here's an example how to fetch 5 posts of the page with the id `523008607856853`.\n\n```js\nconst FacebookGraph = require('facebookgraph');\n\nconst graph = new FacebookGraph('\u003cYour Facebook Access Token\u003e')\nconst posts = await graph.fetch('523008607856853', 'posts', 5)\nconsole.log(posts);\n```\n\n### Request object using ID\n\n```js\nconst zuck = await graph.get('4');\n```\n\n```\n{ id: '4',\n  first_name: 'Mark',\n  last_name: 'Zuckerberg',\n  link: 'https://www.facebook.com/app_scoped_user_id/4/',\n  name: 'Mark Zuckerberg',\n  updated_time: '2017-01-26T08:32:59+0000' }\n```\n\n### Search API\n\nSearch API endpoint is: `https://graph.facebook.com/v2.8/search`. You can search through objects of type `user`, `page`, `event`, `group`, `place`, `placetopic`.\n\nThe payload object has three properties: a search term (`q`), a search type (`type`) property and `fields` of each object. Check out the docs to see which fields can be requested for each object.\n\n```js\nconst pages = await graph.search({ q: 'geek', type: 'page', fields: 'name, link' })\n```\n\nThe code above requests the `name` and `link` fields to be returned which are the part of the page public profile and do not require additional permissions. The Facebook Graph API's `/search` end point only returns publicly available information.\n\nThe syntax for requesting the field of a field is `field{nestedField}`; to request more than one nested field, separate them by commas: `field{nestedField1, nestedField2, nestedField3}`; e.g. specify `photos.limit(2)` to return only 2 photos, or `photos.limit(2){link, comments.limit(3)}` to return only 2 photos but `link` and up to 3 comments for each one.\n\n\n```js\nconst users = await graph.search({ q: 'geek', type: 'user', fields: 'photos.limit(2){link, comments.limit(2)}' }\n```\n\n### Pagination\n\nBy default, `.search` and `.fetch` get only first 25 corresponding elements. It is possible, however, get more results as pagination is already incorporated. There is a 2nd paramater `size` for both `.search` and `.fetch` which defines how many elements should be fetched in total: it can be set either to a particular number or as `Infinity` to go through all the results pages and gather all results\n\n```js\nconst pages = await graph.search({ q: 'geek', type: 'page', fields: 'name, link' }, Infinity)\n```\n\n```js\nconst posts = await graph.fetch('523008607856853', 'posts', 100)\n```\n\n### Posting text messages, photos or videos\n\n```js\nconst post = await graph.post('me', { message: 'This is a test message.', link: 'https://zaiste.net' });\n```\n\nSet `no_story` to hide the post from showing up in the user feed.\n\n### Batch requests\n\n```js\nconst r = await graph.batch([\n  { method: \"GET\", relative_url: \"me\"},\n  { method: \"GET\", relative_url: \"me/friends?limit=10\"}\n])\n```\n\n\n\n[1]: https://github.com/mzabriskie/axios\n[2]: https://github.com/request/request\n[3]: https://developers.facebook.com/docs/graph-api\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaiste%2Ffacebookgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaiste%2Ffacebookgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaiste%2Ffacebookgraph/lists"}