Home - nov/fb_graph2 GitHub Wiki

fb_graph2 Wiki

Deprecations

FbGraph2 gem deprecated several features implemented in FbGraph gem.
See more details Deprecations.

Debugging

If you have troubles and want to see raw HTTP request/response, read Debugging.
Putting raw http response is always better than putting ruby backtrace when reporting FbGraph2 bug.

Access Tokens

FB provide several ways to get access tokens.

  • Using JS SDK
  • Using iOS/Android SDK
  • Raw OAuth2 Flow
  • FB iframe Apps

Since each way has different security characteristics, you should understand them and decide which way is the best for your use-case.
See more details Obtain Access Tokens.

You can also extend existing access token lifetime.
See more details Extending Access Token Lifetime.

Basic Usage

Fetching an Object and its Edges

To use fb_graph2, you shouldn’t need to read its gem documents.
Instead, it follows Facebook Graph API interface in “rubyish” way.

So that once you read the official Facebook Graph API Documents, you should be able to know how to use fb_graph2 for your use-case.

For example, when fetching a User object, your code would be

user = FbGraph2::User.new('user_id').authenticate('access_token')
user.fetch

and the actual API call would be

GET /v2.0/user_id HTTP/1.1
Authorization: Bearer access_token
Host: graph.facebook.com

and user.fetch returns FbGraph::User instance which holds user attributes and edges described in the official document.
Each attributes and edges returns “reasonable” ruby object.

# User Attributes
user.name     # => String
user.email    # => String
user.cover    # => FbGraph2::Photo
user.hometown # => FbGraph2::Page

# User Edges
user.family  # => Array of FbGraph2::User
user.feed    # => Array of FbGraph2::Post
user.picture # => FbGraph2::Struct::Picture

For supported object types, ask object_classes on FbGraph2 module.

FbGraph2.object_classes

For supported edge types, ask edges on an object instance.

user.edges # => Array of String

This is the basic usage of fb_graph2.

I hope you can “feel” how to use this gem.

More UseCases

Will add more code samples & use-cases as your request.

Request more gem documentation

Needs more help?

Open an Issue

⚠️ **GitHub.com Fallback** ⚠️