我在使用带有咖啡脚本的 Facebook api 时遇到问题。每次我这样做FB.getLoginStatus
并且状态为"connected"
时,我都会自动调用FB.api("/me", (data)->console.log(data))
页面重新加载而无需我要求。
console.log
另一个问题是,如果在调用后放置断点并观察数据的值,则会从 Facebook 获取错误。
我想知道我是否可以这样做,以及总体上为什么要重新加载页面。
这是该页面的咖啡脚本代码:
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)