将参数传递给Facebook页面选项卡应用程序(Pass a parameter to Facebook Page Tab app)

编程入门 行业动态 更新时间:2024-10-11 03:17:28
将参数传递给Facebook页面选项卡应用程序(Pass a parameter to Facebook Page Tab app)

我在此URL上有此HTML: https : //myapp.herokuapp.com

<html> <body> <iframe frameborder=0 border=0 scrolling="no" src="<?php echo $_GET['url']; ?>" width="760px" height="521px"></iframe> </body> </html>

我创建了一个Facebook页面标签,我希望任何人都可以使用不同的URL在Facebook页面上安装它。 因此,当您单击FB页面1上的选项卡时,它将显示嵌入的URL1,FB Page 2将显示URL2,依此类推。 然后,在安装“页面”选项卡时,该URL是一个参数。

我试过这个:

https://www.facebook.com/dialog/pagetab?app_id=XXXXXXXXXX&next=https://myapp.herokuapp.com?url=HERE_YOUR_URL

它正在安装应用程序,但似乎iframe中的URL参数为null。 我究竟做错了什么?

谢谢

I have this HTML on this URL: https://myapp.herokuapp.com

<html> <body> <iframe frameborder=0 border=0 scrolling="no" src="<?php echo $_GET['url']; ?>" width="760px" height="521px"></iframe> </body> </html>

I have created a Facebook Page Tab and I want that anyone can install it on their Facebook Page with a different URL. So when you click on the tab on FB Page 1 it would display embedded URL1, FB Page 2 would display URL2, and so on. The URL is, then, a parameter when you install the Page Tab.

I have tried this:

https://www.facebook.com/dialog/pagetab?app_id=XXXXXXXXXX&next=https://myapp.herokuapp.com?url=HERE_YOUR_URL

It is installing the app, but seems that the URL parameter in the iframe is null. What am I doing wrong?

Thanks

最满意答案

我的方法有点不同。

虽然可能无法安装带有URL参数的应用程序,但您可以根据首先加载它们的页面来调整其内容。 正如页面标签Facebook API集成教程所述:

当用户选择您的页面选项卡时,您将收到带有一个附加参数页面signed_request参数。 此参数包含具有id (当前页面的页面ID)的JSON对象( SOURCE )

因此,您将在多个页面上安装相同的应用程序,并在顶部使用以下代码(在您创建$facebook对象后):

$page_id = ""; $sr = $facebook->getSignedRequest(); if($page = $sr['page']) { $page_id = $page['id']; }

您现在应该能够使用$page_id作为唯一标识符,告诉您用户当前正在查看应用程序的页面,而不是$_GET变量。 Switch语句或数据库集成是第一个想到的方法,但您似乎在询问如何识别和检索唯一参数而不是如何使用它,所以我相信您会自己解决这个问题。 :)

注意:这(显然)不适用于安装在同一页面的多个页面选项卡上的应用程序,但这似乎不是您的关注点。

My approach is a little different.

While it may not be possible to install Apps with URL parameters, you could adjust their content depending on which Page loaded them in the first place. As the Page Tab Facebook API Integration Tutorial states:

When a user selects your Page Tab, you will receive the signed_request parameter with one additional parameter, page. This parameter contains a JSON object with an id (the page id of the current page) (SOURCE)

So you would install the same App on several pages, and use the following code at the top (after you've created the $facebook object):

$page_id = ""; $sr = $facebook->getSignedRequest(); if($page = $sr['page']) { $page_id = $page['id']; }

You should now be able to use $page_id as the unique identifier telling you which page the user is currently viewing the application from, instead of a $_GET variable. Switch statements or a database integration are the first methods that come to mind, but you seem to be asking how to identify and retrieve a unique parameter and not how to use it, so I'm sure you will figure this out on your own. :)

Note: This (obviously) will not work on an app being installed on several Page Tabs of the same page, but that doesn't seem to be a concern of yours.

更多推荐

本文发布于:2023-08-03 08:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   应用程序   参数   页面   Facebook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!