-
-
Notifications
You must be signed in to change notification settings - Fork 66
Home
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
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.