尝试运行 FQL 查询并仅在用户登录时打印出结果(登录表单在同一页面上)。
相关代码——
FB.init({
appId: '451320528308299',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl: 'http://URL.COM/channel', // channel.html file
oauth : true // enable OAuth 2.0
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
FB.api({
method: 'fql.multiquery',
queries: {
'query1': 'select status_id, message from status where uid = me()',
'query2': 'select user_id, object_id from like where object_id in (#query1)'
}
},
function(response){
console.log(response);
});
} 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.
}
即使没有登录,上面的代码也会运行$(document).ready
并将输出打印到控制台。我做错了什么?
编辑- 原来我已登录 Facebook.com(但已退出我的应用程序)。我正在打电话req.logout()
(使用带有 ExpressJS 的 Passport 中间件)。