Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Facebook JavaScript SDK in CoffeeScript
# 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 = ->
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.getLoginStatus((data) ->
if (data.status == "connected")
uid = data.authResponse.userID
accessToken = data.authResponse.accessToken;
FB.api("/me", (data) ->
console.log("Hello #{}")
if (response.status == "not_authorized")
# the user is logged in to Facebook,
# but has not authenticated your app
# the user isn't logged in to Facebook.
PageScript = document.getElementsByTagName("script")[0]
return if document.getElementById("FBScript")
FBScript = document.createElement("script") = "FBScript"
FBScript.async = true
FBScript.src = "//"
PageScript.parentNode.insertBefore(FBScript, PageScript)

This comment has been minimized.

Copy link

itsluke commented Jun 26, 2014

Just a quick note,

if (response.status == "not_authorized")

should read

if (data.status == "not_authorized")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.