{"id":19541793,"url":"https://github.com/nullscreen/fb-core","last_synced_at":"2026-02-26T09:43:07.573Z","repository":{"id":56846086,"uuid":"98241919","full_name":"nullscreen/fb-core","owner":"nullscreen","description":"A Ruby client for the Facebook Graph API","archived":false,"fork":false,"pushed_at":"2022-10-30T20:49:55.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-30T12:34:42.336Z","etag":null,"topics":["gem"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nullscreen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-24T22:59:34.000Z","updated_at":"2023-08-23T18:49:38.000Z","dependencies_parsed_at":"2023-01-20T15:56:57.911Z","dependency_job_id":null,"html_url":"https://github.com/nullscreen/fb-core","commit_stats":null,"previous_names":["fullscreen/fb-core"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullscreen%2Ffb-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullscreen%2Ffb-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullscreen%2Ffb-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullscreen%2Ffb-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nullscreen","download_url":"https://codeload.github.com/nullscreen/fb-core/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251025625,"owners_count":21524836,"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":["gem"],"created_at":"2024-11-11T03:11:58.816Z","updated_at":"2026-02-26T09:43:02.517Z","avatar_url":"https://github.com/nullscreen.png","language":"Ruby","readme":"# Fb::Core\n\nFb::Core provides methods to interact with Facebook users and pages through the Facebook Graph API.\n\n[![Build Status](http://img.shields.io/travis/Fullscreen/fb-core/master.svg)](https://travis-ci.org/Fullscreen/fb-core)\n[![Coverage Status](http://img.shields.io/coveralls/Fullscreen/fb-core/master.svg)](https://coveralls.io/r/Fullscreen/fb-core)\n[![Dependency Status](http://img.shields.io/gemnasium/Fullscreen/fb-core.svg)](https://gemnasium.com/Fullscreen/fb-core)\n[![Code Climate](http://img.shields.io/codeclimate/github/Fullscreen/fb-core.svg)](https://codeclimate.com/github/Fullscreen/fb-core)\n[![Online docs](http://img.shields.io/badge/docs-✓-green.svg)](http://www.rubydoc.info/gems/fb-core/frames)\n[![Gem Version](http://img.shields.io/gem/v/fb-core.svg)](http://rubygems.org/gems/fb-core)\n\nThe **source code** is available on [GitHub](https://github.com/Fullscreen/fb-core) and the **documentation** on [RubyDoc](http://www.rubydoc.info/gems/fb-core/frames).\n\n### Installing and Configuring\n\nAdd `fb-core` to your Gemfile and run `bundle install`.\n\nMost methods of this library require to have an access token of a Facebook user.\nIf you need to obtain one programmatically, use the [fb-auth](https://github.com/Fullscreen/fb-auth) library.\n\n## Usage\n\nFb::User#email\n--------------\n\nGiven an user access token with the `email` scope, you can get the user's email by calling:\n\n```ruby\nuser = Fb::User.new access_token: '--valid-access-token--'\nuser.email # =\u003e 'john.smith@example.com'\n```\n\nFb::User#pages\n--------------\n\nGiven an user access token with the `pages_show_list` scope, you can get the list of Facebook pages managed by the user by calling:\n\n```ruby\nuser = Fb::User.new access_token: '--valid-access-token--'\nuser.pages\n# =\u003e [#\u003cFb::Page: id=\"1234\", name=\"sample1\"\u003e, #\u003cFb::Page: id=\"5678\", name=\"sample2\"\u003e]\n```\n\nFb::Page#posts\n--------------\n\nGiven a page with posts, you can get the posts on the page since creation by calling:\n\n```ruby\npage = Fb::Page.new access_token: '--valid-access-token--', id: '--valid-id--'\npage.posts\n# =\u003e [#\u003cFb::Post: id=\"1234\", type=\"video\"\u003e, #\u003cFb::Post: id=\"5678\", type=\"video\"\u003e]\n```\n\nPass `since` (`Time`) and `until` (`Time`) options to get posts in between the two times.\n\n```ruby\noptions = { since: Time.new(2015, 05, 15), until: Time.now }\npage.posts options\n# =\u003e [#\u003cFb::Post: id=\"5678\", type=\"video\"\u003e,..]\n```\n\nPass `with_metrics: true` to include post insights for the following metrics...\nAll post types: `post_engaged_users`\nVideo posts only: `post_video_views_organic`, `post_video_views_paid`, `post_video_views`, and `post_video_view_time`\n\n```ruby\npage.posts with_metrics: true\n# =\u003e [#\u003cFb::Post: id=\"5678\", type=\"video\"\u003e,..]\n```\n\nYou can also combine all three options...\n\n```ruby\noptions = { since: Time.new(2015, 05, 15), until: Time.now, with_metrics: true }\npage.posts options\n```\n\nFb::Page#like_count\n--------------\n\nGiven a page, you can get the the number of likes for the page.\n\n```ruby\npage = Fb::Page.new access_token: '--valid-access-token--', id: '--valid-id--'\npage.like_count\n# =\u003e 15000\n```\n\nPass an `until` (`Date`) option to get the count at a certain date.\n\n```ruby\npage.like_count until: Date.today - 7\n# =\u003e 10000\n```\n\nFb::Page#view_count\n--------------\n\nYou can also get the the number of views for the page.\n\n```ruby\npage = Fb::Page.new access_token: '--valid-access-token--', id: '--valid-id--'\npage.view_count\n# =\u003e 12345\n```\n\nPass an `until` (`Date`) option to get the count at a certain date.\n\n```ruby\npage.view_count until: Date.today - 7\n# =\u003e 10000\n```\n\nFb::Page#weekly_insights\n--------------\n\n`weekly_insights` allows you to get metrics that are available weekly such as\n`page_views_total`, `page_impressions`, `page_fan_adds`, etc. Refer to\n[metrics](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#availmetrics)\nfor a list of available weekly metrics.\n\nThis method takes an array metrics and returns a hash of the metrics mapped to\ntheir values. Each metric value is the sum of the last 7 days. If today is July 20th,\nthen the values will be for July 14 - July 20.\n\n```ruby\nmetrics = %i(page_impressions page_fan_adds)\npage = Fb::Page.new access_token: '--valid-access-token--', id: '--valid-id--'\npage.weekly_insights metrics # sum for July 14 - 20\n# =\u003e {:page_impressions =\u003e 1234, :page_fan_adds =\u003e 5678}\n```\n\nPass an `until` (`Date`) option such as `Date.today - 7` to fetch 7 days prior to July 14th.\n\n```ruby\npage.weekly_insights metrics, until: Date.today - 7  # sum for July 8 - 14\n# =\u003e {:page_impressions =\u003e 1234, :page_fan_adds =\u003e 5678}\n```\n\nFb::Page#metric_insights\n--------------\n\nYou can get an individual metric through using `metric_insights` which takes a\nmetric, period, and options (since \u0026 until). Refer to\n[metrics](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#availmetrics)\nfor a list of available metrics and periods.\n\n**Ensure that the period that you are using is supported by the metric**.\nFor example, `page_views_total` (page views) is available for `day`, `week`, and `days_28`\nwhereas `page_fans` (page likes) is only available as `lifetime`.\n\n`metric_insights` returns a hash of Dates mapped to values. Passing `since` only return dates ahead\nto this date (lower bound) and passing `until` will return dates previous to this day\n(upper bound \u0026 defaults to 2 days ago). Combining both options will return the dates in between.\n\n```ruby\npage = Fb::Page.new access_token: '--valid-access-token--', id: '--valid-id--'\nmetric_insights = page.metric_insights 'page_views_total', :day # let today be August 7th\n# =\u003e {#\u003cDate: 2017-08-04\u003e =\u003e 598, \u003cDate: 2017-08-05\u003e =\u003e 548}\n```\n\nWith `until` (`Date`) and `since` (`Date`).\n\n```ruby\noptions = {since: Date.today - 9, until: Date.today}\nmetric_insights = page.metric_insights metric, :day, options\n# =\u003e {#\u003cDate: 2017-08-01\u003e =\u003e 639,..,#\u003cDate: 2017-08-05 =\u003e 548}\n```\n\n## Development\n\nTo run tests, obtain a long-term access token for a Facebook user who manages\nat least one page and includes `email` and `manage_pages` scopes. Set the token as:\n\n    export FB_TEST_ACCESS_TOKEN=\"YourToken\"\n\nThen, run `rake spec` to run the tests.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\nThanks :tada:\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullscreen%2Ffb-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnullscreen%2Ffb-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullscreen%2Ffb-core/lists"}