how to get facebook page id inside page fan tab using facebook javascript sdk(如何使用 facebook javascript sdk 在页面粉丝选项卡内获取 facebook 页面 id)
问题描述
我正在尝试创建一个网络应用程序,为 Facebook 页面创建粉丝标签...
I'm tring to create a web app that create a fan tabs for facebook pages ...
我的问题是……
我试过这个:-
FB.api(
"/{page-id}/feed",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
如何使用 facebook javascript sdk 获取页面粉丝标签内的 facebook 页面 ID?
How to get facebook page id inside page fan tab using facebook javascript sdk ?
这是描述我想要做什么的图像:http://www.wtttc.com/image.php?id=25
this is image describing what I want to do : http://www.wtttc.com/image.php?id=25
我什么都试过了,但没有用:(
I tried everything but no use :(
谢谢
推荐答案
为了获取粉丝页的page id,需要从Facebook获取signed_request.https://developers.facebook.com/docs/facebook-login/using-login-with-games#checklogin其实这个链接讲的是cavas页面,但是对于fan page的原理是一样的.
In order to get the page id of fan page, you need to get the signed_request from Facebook. https://developers.facebook.com/docs/facebook-login/using-login-with-games#checklogin In fact, this link talk about the cavas page, but it's the same principle for the fan page.
但是如果你仔细查看获取这个变量的方法,你会发现,
But if you look carefully the way to get this variable, you can find that,
签名的请求通过 HTTP POST 发送到在应用仪表板中设置为画布 URL 的 URL.
The signed request is sent via an HTTP POST to the URL set as your Canvas URL in the App Dashboard.
这意味着,如果你想获得一个签名的请求数据,你应该通过一个 HTTP POST 来获得它.仅使用 javascript 无法获取粉丝页面的页面 id.Javascript 是一种客户端语言,因此您无法访问 POST 数据.您需要做的只是将您的 javascript 代码放入 .jsp/.php/... 或任何其他服务器端语言页面.通过服务器端语言页面,您获得签名请求并将其传递给您的 javascript 代码.以下是 JSP 中的示例:
Which means, if you want to get a signed request data, you should get it through a HTTP POST. To get the page id of fan page is not possible just using javascript. Javascript is a client side language, so you can't access the POST data. What you need to do is just put your javascript code into a .jsp/.php/...or any other server-side language page. Through the server-side language page, you get the signed request and pass it to your javascript code. Here is an example in JSP:
<%String signedRequest = request.getParameter("signed_request");%><script>window.signedRequest = "<%=signedRequest%>"</script>
在你的 javascript 中,只需解码你得到的字符串,它将包含页面 id.
And in your javascript, just decode the string you got and it will contain the page id.
var signedRequest = global.signedRequest;
var data1 = signedRequest.split('.')[1];
data1 = JSON.parse(base64decode(data1));
console.log(data1);
然后你可以得到这样的数据:
Then you can get data like this:
Object {algorithm: "HMAC-SHA256", expires: 1404925200, issued_at: 1404921078, oauth_token: "CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPp…Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD", page: Object…}
算法:HMAC-SHA256"过期:1404925200发布时间:1404921078组oauth_token: CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPpFRfM1ln3x9pb7mLBujyug5iHUifSnyxmPHOLe030wI3H5DYXubnxbPhww9aipSnwoEr6lwctuQaGKxYvDBdZCNuFiaYIduORTWirmZC2rKL86Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD"页面:对象用户:对象用户 ID:1519950734891144"原型:对象
algorithm: "HMAC-SHA256" expires: 1404925200 issued_at: 1404921078 oauth_token: "CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPpFRfM1ln3x9pb7mLBujyug5iHUifSnyxmPHOLe030wI3H5DYXubnxbPhww9aipSnwoEr6lwctuQaGKxYvDBdZCNuFiaYIduORTWirmZC2rKL86Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD" page: Object user: Object user_id: "1519950734891144" proto: Object
在page对象中,可以找到page id.
In the page object, you can find page id.
Object {id: "1522695611287219", liked: true, admin: true}
关于如何解码签名请求,可以看这个链接https://developers.facebook.com/docs/facebook-login/using-login-with-games#checklogin方法一样.
About how to decode the signed request, you can see this link https://developers.facebook.com/docs/facebook-login/using-login-with-games#checklogin It's the same way.
希望对你有帮助.
这篇关于如何使用 facebook javascript sdk 在页面粉丝选项卡内获取 facebook 页面 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 facebook javascript sdk 在页面粉丝选项卡内
基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01