Facebook API在“页面”选项卡中获取Fanpage ID [英] Facebook API get Fanpage ID inside Page Tab

查看:117
本文介绍了Facebook API在“页面”选项卡中获取Fanpage ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Facebook应用程序(页面选项卡)。此应用程序可以添加到粉丝页。

在此应用程序中,我使用Javascript进行调用,以获取适用于我应用程序的JSON数据。

I created a Facebook App (Page Tab). This App can be added to Fanpages.
In this App, I make a call with Javascript to get the right JSON Data for my App.

数据是特定于我的应用程序被添加到FB的站点。

即可当可口可乐将我的应用程序添加到他们的粉丝页面时,我需要知道这是可口可乐才能获取正确的数据。

The data is specific to the FB-Site where my App was been added.
I.e. when Coca-Cola adds my App to their Fan Page, I need to know that is coca cola - to get the right data.

现在,我的想法是创建页面选项卡,从页面保存ID。当拨打页面选项卡中的数据时,发送Fanpage ID作为参数。

Now, my Idea is when creating the Page Tab, save the ID from the Page. And when making a call to get the data in the page tab sending the Fanpage ID as a parameter.

我希望我的意思相当清楚。

I hope it is reasonably clear what I mean.

我的问题是,如何访问ID这一页?
最好用Javascript。或者这是不可能的吗?

My Question is, how got access to ID of the Page? Best with Javascript. Or is this not possible?

我会感谢任何提示!

推荐答案

p>这将是非常容易与PHP SDK。一个 signed_request 参数将传递给您的iframe,PHP SDK提供了一个名为 getSignedRequest()的函数来解析它:

This would be very easy with the PHP SDK. A signed_request parameter will get passed on to your iframe, and the PHP SDK offers a function called getSignedRequest() to parse it:

https://developers.facebook.com/docs/reference/php/facebook-getSignedRequest/

例如:

$sr = $fb->getSignedRequest();
echo $sr['page']['id'];

使用JavaScript会变得更加复杂。您可以尝试获取signed_request参数,如下所示:如何从JavaScript中检索GET参数? - 但你必须自己处理参数。以下是使用PHP解析您自己的参数: https://developers.facebook.com/docs/facebook-login/using-login-with-games

With JavaScript it would be a lot more complicated. You could try to get the signed_request parameter like this: How to retrieve GET parameters from javascript? - But you would have to deal with the parameter on your own. Here´s how to parse the parameter on your own with PHP: https://developers.facebook.com/docs/facebook-login/using-login-with-games

在这种情况下,不需要Facebook SDK,顺便说一句。而且它也可以用PHP< 5.4。

No Facebook SDK needed in that case, btw. And it should also work with PHP <5.4.

这篇关于Facebook API在“页面”选项卡中获取Fanpage ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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