Created
September 16, 2011 02:00
-
-
Save jamesladd/1221007 to your computer and use it in GitHub Desktop.
Using Facebook API server side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'koala' | |
# | |
# initialize a Graph API connection | |
@oauth = Koala::Facebook::OAuth.new(app_id, app_secret, "https://www.facebook.com/connect/login_success.html") | |
@url_for_oauth_code = @oauth.url_for_oauth_code(:permissions => "publish_stream") | |
puts @url_for_oauth_code.inspect | |
@your_oauth_token = "goto above printed url and copy code= upto # into this string, then run again." | |
@your_oauth_token = @oauth.get_access_token(@your_oauth_token) | |
puts @your_oauth_token | |
# first, initialize a Graph API with your token | |
puts @graph = Koala::Facebook::GraphAPI.new(@your_oauth_token) | |
@friends = @graph.get_connections("me", "friends") | |
puts @friends.inspect | |
@friend = @friends[0] | |
puts "Getting info about me" | |
@me = @graph.get_object("me") | |
puts @me.inspect | |
puts "Getting more info on a friend." | |
@detail = @graph.get_object(@friend['id']) | |
puts @detail.inspect | |
puts "Writing public data ..." | |
# now try writing to own wall. | |
puts @graph.put_wall_post("hey, i'm learning kaola slowly").inspect | |
#now try writing to friends wall | |
puts @friend['id'] | |
puts @graph.put_wall_post("I can't believe not butter - simon.", {}, @friend['id']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment