How to post on my friend's Facebook Wall using koala gem? - ruby-on-rails

I am trying to post a message on my friend's Facebook wall using Koala Gem in my Web Application.
I am trying using the following code
#user.put_wall_post("Hey, Welcome to the Web Application!!!!",{:name => "Friend's Name"} )
I have also tried replacing the name of my friend with his Facebook Id, but it is of no help...
#user.put_wall_post("Hey, Welcome to the Web Application!!!!",{:name => "10001010101010"} )
But, both the above methods post the message on my wall. What am I wrong with??

The name symbol doesn't represent the name of the user on Facebook but the title of the message! Try this instead:
#user.put_wall_post("Hey, Welcome to the Web Application!!!!", {:name => "..."}, "id_of_your_friend")
Tell me if it works.

Related

RoR fb_graph application feed

I am using fb_graph gem for Ruby on Rails. I want to post a message on wall but the problem is that when I post the message (feed) it is posted by my user instead of my application, on the application's wall..
so it looks like
Name Surname
message content
via application_name
and I want it to be
application_name
message content
My code is:
application = FbGraph::Application.new(app_id).fetch
application.feed!(:message => 'test', :access_token => access_token)
I have found solution to this question. I have generated access token for application instead of user. This can be found on https://developers.facebook.com/docs/authentication/

Using fb_graph to post to Facebook fan page from Rails 3

I hear that fb_graph is the way to go and I already have my app registered with Facebook but I don't know how to get the access token to post things. I have my app ID and secret but I need to get that access token. All I'm trying to do is post to a Facebook fan page (as the page).
How do I get the access token?
Get the user:
user = FbGraph::User.me(access_token)
user.fetch
To see the users accounts details:
user.accounts
Select the Facebook page that you want to post to:
account = user.accounts.select {|account| account if account.name == "*Your Page Name*"}.first
(account.access_token => the pages access token)
(account.identifier => page id)
Create new page instance:
page = FbGraph::Page.new(account.identifier)
Post to the page:
note = page.note!(:access_token => account.access_token, :subject => "Hello World", :message => "hey, this is a test from rails")
The step-by-step procedure for access token with Oauth 2.0 is found here: http://developers.facebook.com/docs/authentication/. If you require a sample code in Ruby, create a new app and under "Hosting URL", click on "get one" and select Ruby programming language when prompted. It also contains code to pull from Graph API.
I highly highly recommend the new gem Koala for working with facebook.
If you do a call to https://graph.facebook.com/me/accounts
and pass in your access_token it will return data listing all the pages you have access to and the access_tokens needed to post to those walls.#
You get your access token by logging in and the access token is passed back by the login process.

verifying success of posting to a user's wall feed using "fb_graph" 1.9.2 on rails

Is there a way to tell if posting to a user's wall was successful? As in:
me = FbGraph::User.me(ACCESS_TOKEN)
me.feed!(
:message => 'Updating via FbGraph',
)
How is the best way to know if it actually made it on their wall?
When you successfully post to a user's feed the return value is the post ID of the newly created post.
See the documentation here:
https://developers.facebook.com/docs/reference/api/user/#statuses

How to pass an access token with KOALA gem for facebook real time updates for feeds and posts

I am trying to develop a facebook integration to fetch the wall posts using KOALA Gem (1.1.0), and Rails 2.3.8 . I can easily generate user_access_token and page_access_token and able to get data using graph API. But when I am using realtime update I can't get datas which need access token. I can access all public information with KOALA api.
I guess we need to pass access_token(user_access_token or page_access_token). I couldn't find an option to pass access token. I checked the RealTimeUpdate class and found only two arguments app_access_token and app_id, which may not be sufficient to get the protected data like feeds and post
Here am attaching the sample code:
#updates = Koala::Facebook::RealtimeUpdates.new(:app_id => YOUR_APP_ID, :secret => YOUR_APP_SECRET )
=> Koala::Facebook::RealtimeUpdates:0x10331fb88 #graph_api=#, #secret=”81297xxxxxxxxxxx”, #app_access_token=”1779yyyyyyy|xxxxxxx”, #app_id=”1779yyyyy”
and you can see app_access_token and access_token has been set the same.
Then I tried to retrieve the access token as follows but it returns nil.
>> #updates.access_token
=> nil
Kindly advise how do I go forward?
Seems this is a bug in facebook . Please have a look #
http://bugs.developers.facebook.net/show_bug.cgi?id=18048

How do you get an ID of a friend? facebooker2. rails

I am using facebooker2 and mogli gem to interact with facebook open graph.
My question is how can I get the ID of my friend so I can post him/her sth on his/her wall? All I can do is post to lets say first friend on my list of friends with the following code:
client = current_facebook_client
#user = Mogli::User.find("me", client) unless(client.blank?)
#friends = Mogli::User.find("me/friends", client) unless(client.blank?)
#page = Mogli::Page.find(#friends.first.id)
post = Mogli::Post.new(:message => "Test message at #{Time.now} (sorry, i'll delete it)")
client.post("#{#user.id}/feed", nil, post)
I was playing around with passing it the names of friends and trying some other stuff. I searched google and I also searched through facebook dev forum. But I just dont know how could I do this. How can I get the ID of a friend that I want to post to?
Thank you for any answers!
Trying doing
puts #friends
and see what data log shows. I guess
#friends = Mogli::User.find("me/friends", client) unless(client.blank?)
returns an array of Hashes. And a key for every friend is returned

Resources