-
-
Notifications
You must be signed in to change notification settings - Fork 66
Home
FbGraph2 gem deprecated several features implemented in FbGraph gem.
See more details Deprecations.
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.
If you have any errors when using fb_graph2, debug actual Graph API response.
By calling FbGraph2.debug!
on top of your code, you’ll see actual HTTP request & response in your console.
FbGraph2.debug!
## NOTE: You can set your own logger too.
# FbGraph2.logger = Rails.logger
me = FbGraph2::User.me(ACCESS_TOKEN).fetch
me.feed! message: 'Hello World'
Since Graph API response format sometimes changes without notice, fb_graph2 might causes errors because of the change.
If you find any such issues, open issue please. (Pull requests are GREAT!)
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.
Will add more code samples & use-cases as your request.