使用facebook javascript sdk检查用户是否喜欢facebook fanpage
我是facebook应用程序开发的新手! 所以我有一个新的项目,使用FacebookSDK来显示FacebookPluginFanpage,如果使用的是connect,而不是这个fanpage的话 我的代码html.index使用facebook javascript sdk检查用户是否喜欢facebook fanpage,javascript,jquery,facebook,facebook-graph-api,facebook-javascript-sdk,Javascript,Jquery,Facebook,Facebook Graph Api,Facebook Javascript Sdk,我是facebook应用程序开发的新手! 所以我有一个新的项目,使用FacebookSDK来显示FacebookPluginFanpage,如果使用的是connect,而不是这个fanpage的话 我的代码html.index <html> <body> <div id="fb-root"></div> <fb:like href="https://www.facebook.co
<html>
<body>
<div id="fb-root"></div>
<fb:like href="https://www.facebook.com/mypage" layout="standard" action="like" show_faces="true" share="true"></fb:like>
</body>
</html>
但是插件总是显示没有
我需要当用户连接,不喜欢这个页面,插件显示
一个问题!为什么respone UserId与我的配置文件Id不同?您可以在后端执行此操作。我听说使用PHP很方便,但我是一个Java爱好者,所以我将告诉你我是如何使用Java做到这一点的。我有一个servlet,我称之为FanGateServlet。它所做的是在你访问该应用程序时获取我的Facebook发送的签名请求,对其进行解码,以确定用户是否喜欢该页面使用servlet的doPost方法
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String signedReq = request.getParameter("signed_request");
if (signedReq == null) {
logger.warn("ERROR: Unable to retrieve signed_request parameter");
response.sendRedirect(appDomain+"/default.html");
} else {
Base64 base64 = new Base64();
// split request into signature and data
String[] signedRequest = signedReq.split("\\.", 2);
// parse signature
// String sig = new String(base64.decode(signedRequest[0].getBytes("UTF-8")));
// parse data and convert to json object
String data = new String(base64.decode(signedRequest[1].getBytes("UTF-8")));
// check whether the user has 'liked' the page
boolean isLikedPage = data.contains("\"page\":{\"id\":\"xxxxxxxxxxxxxxxxxx\",\"liked\":true");
if (isLikedPage) {
response.sendRedirect(appDomain+"/home.html");
}else{
response.sendRedirect(appDomain+"/like-page.html");
}
}
}
}
XXXXXXXXXXXXXXXXXXXX-这是您的页面id。
home.html-向喜欢你的页面的粉丝展示的页面。
like-page.html-向尚未喜欢您的页面的用户显示的页面
要使其工作,您的应用服务器中应该有jar。(不是项目库文件夹)
还有一件更重要的事情,在Facebook开发者设置中,在页面选项卡设置下,页面选项卡Url应该是指向servlet模式的Url
http://appDomain/fangate.do
当然,在web.xml中,您应该将fangate.do映射映射到您的FanGateServlet.java
您不仅可以读取已签名的请求以查看用户是否喜欢您的页面(在javascript sdk中没有获得用户权限),在我的例子中,我还想发送参数。您可以使用app_数据来完成此操作。如果还有更多的事情需要解释,请告诉我。:) 你需要让用户登录,并授予你的用户许可证,任何方式没有登录!谢谢这将是一个安全问题。如果这是一个页面选项卡应用程序,您将在已签名的请求中获得一个喜欢的属性。否则没有
http://appDomain/fangate.do