Created
December 22, 2010 14:09
-
-
Save wildfalcon/751553 to your computer and use it in GitHub Desktop.
Read the fb cookie, and load the user based on the information there
This file contains hidden or 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 'net/https' | |
class User < ActiveRecord::Base | |
after_create :pull_profile_from_facebook | |
def profile_url(size = "square") | |
"https://graph.facebook.com/#{uid}/picture?type=square" | |
end | |
private | |
def pull_profile_from_facebook | |
uri = URI.parse(URI.escape("https://graph.facebook.com/#{uid}?access_token=#{access_token}")) | |
puts uri.request_uri | |
http_session = Net::HTTP.new(uri.host, uri.port) | |
http_session.use_ssl = true | |
res = http_session.start { |http| | |
http.get(uri.request_uri) | |
} | |
self.attributes = JSON.parse(res.body).slice("name", "email") | |
self.save! | |
end | |
end |
This file contains hidden or 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
<div id="fb-root"></div> | |
<script src="http://connect.facebook.net/en_US/all.js"></script> | |
<script> | |
FB.init({appId: '<%= ENV["FB_APP_ID"] %>', status: true, cookie: true, xfbml: true}); | |
FB.Event.subscribe('auth.sessionChange', function() {window.location.assign("/");}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment