简体   繁体   中英

Post to facebook using Graph API and ruby

I'm playing with facebook Graph API and wanted to post to my timeline using ruby.

While posting using only URL I used

 "http://graph.facebook.com/facebook_id/feed?method=POST&access_token=access_token&message=message&link=balhblah.com&actions=%7B%20%22name%22:%22Download%%22,%20%22link%22:%22http://blahblah.com%22%20%7D&name=NAME&caption=caption&description=description"

and it worked perfectly. But I want to do that using ruby. So I used

open("http://graph.facebook.com/facebook_id/feed?method=POST&access_token=access_token&message=message&link=balhblah.com&actions=%7B%20%22name%22:%22Download%%22,%20%22link%22:%22http://blahblah.com%22%20%7D&name=NAME&caption=caption&description=description")

but I'm getting OpenURI HTTP Error 400 BAD request. I required 'open-uri' gem also. Am I doing something wrong? I'm a newbie in ruby

Instead of posting directly using https requests to the Facebook API, why not use a library? Koala is a good option. With that, something like this would post on your wall:

require 'koala'
@api = Koala::Facebook::API.new(oauth_access_token)
@api.put_wall_post(process_result(fql))

You need to gem install koala and to setup your oauth_access_token before using Koala. Check Koala's readme for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM