Created
February 28, 2013 11:01
-
-
Save shavit/5055943 to your computer and use it in GitHub Desktop.
Facebook JavaScript SDK in CoffeeScript
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
# | |
# You should add the Facebook App ID and the channel url (optional), in the #fb-root element, as a data- attribute: | |
# <div id="fb-root" data-app-id="<%= ENV['FACEBOOK_APP_ID'] %>" data-channel-url="<%= url_no_scheme('/channel.html') %>"></div> | |
# | |
window.fbAsyncInit = -> | |
FB.init | |
appId: document.getElementById("fb-root").getAttribute("data-app-id") | |
channelUrl: document.getElementById("fb-root").getAttribute("data-channel-url") | |
status: true, | |
cookie: true, | |
xfbml: true | |
FB.Event.subscribe('auth.login', (response) -> | |
window.location = window.location | |
) | |
FB.Canvas.setAutoGrow() | |
FB.getLoginStatus((data) -> | |
if (data.status == "connected") | |
uid = data.authResponse.userID | |
accessToken = data.authResponse.accessToken; | |
FB.api("/me", (data) -> | |
console.log("Hello #{data.name}") | |
) | |
else | |
if (response.status == "not_authorized") | |
# the user is logged in to Facebook, | |
# but has not authenticated your app | |
else | |
# the user isn't logged in to Facebook. | |
) | |
PageScript = document.getElementsByTagName("script")[0] | |
return if document.getElementById("FBScript") | |
FBScript = document.createElement("script") | |
FBScript.id = "FBScript" | |
FBScript.async = true | |
FBScript.src = "//connect.facebook.net/en_US/all.js" | |
PageScript.parentNode.insertBefore(FBScript, PageScript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a quick note,
should read