我已經閱讀了很多相關的話題在這裏關於這個問題,但我仍然不能夠做這樣的事檢查用戶是否喜歡頁面或不
http://www.facebook.com/Dominos/app_252492331452398
下面是我使用
代碼這是我的問題。
- 所以我已經登錄到我的Facebook頁面
- 如果我去上面的多米諾骨牌網址,我可以相同的或不同的頁面。多米諾骨牌的內容根據我是否喜歡或不同於網頁而改變。但他們並沒有要求我們再次登錄
在我的代碼下面,雖然我已經登錄了我的臉書。我沒有訪問我的用戶信息,直到我點擊登錄按鈕並在提供的彈出窗口中再次登錄。隨着多米諾骨牌在做,我怎麼能跳過這一步。我越來越response.status作爲NOT_AUTHORIZED
- 我知道一旦我登錄,我可以這樣做,以檢查用戶是否喜歡我的網頁或不
VAR的查詢= FB.Data。查詢('從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>
相關/ DUP:http://stackoverflow.com/questions/6246449/facebook-how-to-check-if-user-has-liked-page-and-show-content – ripper234 2012-10-23 15:39:55