问题描述
我已经阅读了很多关于这个问题的相关主题,但是我仍然无法做这样的事情。
I have read a lot of related topics here regarding this problem but I am still not able to do something like this
以下是我正在使用的代码
Below is the code i am using
这是我的问题。
- 所以我已经登录到我的Facebook页面
- 如果我去上面的dominos url,我可以喜欢或不同的页面。多米诺骨牌内容根据我是喜欢还是不喜欢页面而改变。但是他们并不要求我们再次登录
-
在下面的代码中,虽然我已经登录了我的Facebook。我不能访问我的userinfo,直到我点击登录按钮,并在提供的弹出窗口中再次登录。多米诺骨牌在做什么,我怎么能跳过这个步骤呢?我得到response.status作为not_authorized
- So I am already logged in into my facebook page
- If I go to the above dominos url, i can like or unlike the page. The dominos content changes based on whether I have liked or unlike the page. But they are not asking we to log in again
In my code below although I already logged in my facebook. i don't get access to my userinfo until I click login button and login in again in the provided popup. how can I skip this step as the dominos is doing. I am getting response.status as not_authorized
- 我知道一旦我登录,我可以做一些事情来检查用户是否喜欢我的page / not
var query = FB.Data.query('select page_id from page_fan where uid ='+ response.authResponse.userID + '和page_id ='+ PAGE_ID);
var query = FB.Data.query( 'select page_id from page_fan where uid='+response.authResponse.userID+' and 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>
推荐答案
您可以以编程方式执行此操作,不一定只是在标签的上下文中。
You can do this in a programmatic way as well, not necessarily just in the context of a tab.
请注意,您需要在O-Auth连接对话框中请求用户的user_likes权限。
Note that it will require you to ask for the "user_likes" permission from the user in your O-Auth connect dialog.
此代码片段将测试有人目前是否喜欢某些内容:
This code snippet will test for whether someone currently likes something or not:
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。事件订阅:
If you want to catch the event when the user clicks the like button, then you can use FB.Event.subscribe:
FB.Event.subscribe('edge.create',
function(response) {
//Do stuff when the user just clicked a "like" button
}
);
这篇关于检查用户是否喜欢页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!