Friday 19 August 2016

Posting on Facebook Through Ruby On Rails

Here we go to post a link on Facebook with th help of Koala gem.

Koala is a Facebook library for Ruby, supporting the Graph API.

Installation - 

gem "koala", "~> 2.2"

Graph API

The Graph API is the simple, slick new interface to Facebook's data.
Using it with Koala is quite straightforward.  First, you'll need an access token, which you can get through
Facebook's Graph API Explorer (click on 'Get Access Token').

Then, go exploring:

@user = Koala::Facebook::API.new(access_token)


Use that access_token to set this new @user. Now whenever you mention "me" in any Graph API request on a @user, you'll be mentioning this user (@user) as the target for that request. "me" is just the facebook ID for the user itself.

Now you can post to your user's feed.

@user.put_connections("me", "feed", :message => "I am writing on my wall!")

For posting a link -

@user.put_wall_post("message",{link: item_url}, "me").

Thats it.

Cheer Up !!!!

No comments:

Post a Comment