コーヒースクリプトで Facebook API を使用すると問題が発生します。FB.getLoginStatus
ステータスがになるたびに、要求せずにページのリロードを自動的"connected"
に呼び出します。FB.api("/me", (data)->console.log(data))
console.log
もう 1 つの問題は、呼び出しの後にブレークポイントを配置してデータの値を監視すると、Facebook からエラーが発生することです。
これがうまくいくかどうか、そして全体的にページがリロードされる理由を知りたいです。
このページの coffeescript コードは次のとおりです。
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) ->
console.log(data)
if (data.status == "connected")
uid = data.authResponse.userID
accessToken = data.authResponse.accessToken;
FB.api("/me", (data) ->
console.log(data) // Here is the last call before the reload
)
else if (data.status == "not_authorized")
console.log("Je suis log a facebook")
$("#FBConnect").on("click", (e) ->
FB.login( (response) ->
if response.authResponse
console.log('Welcome! Fetching your information.... ');
FB.api('/me', (response) ->
console.log('Good to see you, ' + response.name + '.');
)
else
console.log('User cancelled login or did not fully authorize.');
)
)
# the user is logged in to Facebook,
# but has not authenticated your app
else
console.log("Je ne suis pas connecte a facebook")
# 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)