-
-
Notifications
You must be signed in to change notification settings - Fork 65
Home
FbGraph2 gem deprecated several features implemented in FbGraph gem.
See more details Deprecations.
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.
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.
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.fetchand the actual API call would be
GET /v2.0/user_id HTTP/1.1
Authorization: Bearer access_token
Host: graph.facebook.comand 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::PictureFor supported object types, ask object_classes on FbGraph2 module.
FbGraph2.object_classesFor supported edge types, ask edges on an object instance.
user.edges # => Array of StringThis 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.