我在这里已经阅读了很多关于这个问题的相关主题,但我仍然无法做到这样的事情
http://www.facebook.com/Dominos/app_252492331452398
以下是我正在使用的代码
这是我的问题。
在我的代码中,虽然我已经登录了我的脸书。在我单击登录按钮并在提供的弹出窗口中再次登录之前,我无法访问我的userinfo。我怎么能像多米诺骨牌一样跳过这一步。我收到response.status作为not_authorized
var query = FB.Data.query('从page_fan中选择page_id,其中uid ='+ response.authResponse.userID +'和page_id ='+ PAGE_ID);
这是代码
<!DOCTYPE html>
<html>
<head>
<title>Fbjquery</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="fb-root"></div>
<h2>Updated JS SDK example</h2><br />
<div id="user-info"></div>
<p><button id="fb-auth">Login</button></p>
<script>
window.fbAsyncInit = function() {
FB.init({ appId: 'App_ID',
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
var button = document.getElementById('fb-auth');
console.log("inside update button "+response.authResponse);
if (response.authResponse) {
console.log(response.authResponse);
//user is already logged in and connected
var userInfo = document.getElementById('user-info');
FB.api('/me', function(response) {
userInfo.innerHTML = '<img src="https://graph.facebook.com/'
+ response.id + '/picture">' + response.name;
button.innerHTML = 'Logout';
});
button.onclick = function() {
FB.logout(function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML="";
});
};
} else {
//user is not connected to your app or logged out
button.innerHTML = 'Login';
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML =
'<img src="https://graph.facebook.com/'
+ response.id + '/picture" style="margin-right:5px"/>'
+ response.name;
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'email'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
答案 0 :(得分:3)
您也可以采用编程方式执行此操作,而不仅仅是在选项卡的上下文中。
请注意,它需要您在O-Auth连接对话框中询问用户的“user_likes”权限。
此代码段将测试某人当前是否喜欢某事:
FB.api('/me/likes/MY_PAGE_ID', {limit: 1}, function(r) {
if (r.data.length == 1) {
//do stuff when the user is a liker
} else {
//do stuff when the user is not currently a liker
}
});
如果您想在用户点击“赞”按钮时捕获该事件,则可以使用FB.Event.subscribe:
FB.Event.subscribe('edge.create',
function(response) {
//Do stuff when the user just clicked a "like" button
}
);
答案 1 :(得分:2)
在Facebook粉丝页面上,当用户点击“赞”按钮时,整个页面都会重新加载,Facebook会使用名为signed_request的参数向您的网站发送HTTP帖子,您需要解码并查看服务器代码。记录了{em>签名请求 here。解码后,您需要查看 page.liked 值。
可能会有所帮助: