如何使用facebook javascript sdk在页面粉丝选项卡中获取Facebook页面ID [英] how to get facebook page id inside page fan tab using facebook javascript sdk

查看:68
本文介绍了如何使用facebook javascript sdk在页面粉丝选项卡中获取Facebook页面ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个为Facebook页面创建粉丝标签的网络应用程序......

I'm tring to create a web app that create a fan tabs for facebook pages ...

我的问题是......

my problem is ...

我试过这个: -

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 :(

谢谢你

推荐答案

要获取粉丝页面的页面ID,您需要从Facebook获取signed_request。
https://developers.f acebook.com/docs/facebook-login/using-login-with-games#checklogin
实际上,这个链接谈论了cavas页面,但它与粉丝页面的原理相同。

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发送到在App Dashboard中设置为Canvas 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
issued_at:1404921078
组oauth_token:CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPpFRfM1ln3x9pb7mLBujyug5iHUifSnyxmPHOLe030wI3H5DYXubnxbPhww9aipSnwoEr6lwctuQaGKxYvDBdZCNuFiaYIduORTWirmZC2rKL86Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD
页面:对象
用户:对象
user_id:1519950734891144
proto :对象

algorithm: "HMAC-SHA256" expires: 1404925200 issued_at: 1404921078 oauth_token: "CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPpFRfM1ln3x9pb7mLBujyug5iHUifSnyxmPHOLe030wI3H5DYXubnxbPhww9aipSnwoEr6lwctuQaGKxYvDBdZCNuFiaYIduORTWirmZC2rKL86Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD" page: Object user: Object user_id: "1519950734891144" proto: Object

在页面对象中,您可以找到页面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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆