简体   繁体   English

在Facebook canvas应用中访问POST数据

[英]Accessing POST data in Facebook canvas app

I've got a simple form in my canvas / iframe Facebook app, and I'm trying to pass along the values as POST. 我的canvas / iframe Facebook应用程序中有一个简单的表单,我试图将这些值作为POST传递。 Now from reading all about this all over SO and FB's latest docs, as I understand it, all data send via a POST form can be accessed on the receiving end from the $_REQUEST object. 现在,据我所知,通过阅读SO和FB最新文档中的所有内容,可以通过$ _REQUEST对象在接收端访问所有通过POST形式发送的数据。

I also read on another thread on SO that in order for POST forms to work you need to pass along an input named "signed_request" with the value as the current signed_request (I have the signed request working ok otherwise...all login and authentication stuff working fine). 我还在SO上的另一个线程上读到,为了使POST表单正常工作,您需要传递一个名为“ signed_request”的输入,并将其值作为当前的signd_request(我让签名的请求正常工作,否则...所有登录和身份验证工作正常)。 This isnt mentioned anywhere in the official FB docs. 官方FB文档中的任何地方都没有提到这一点。

So my problem is that all that comes back in the $_REQUEST object is the signed request, and a bunch of other session stuff. 所以我的问题是,返回到$ _REQUEST对象的所有内容都是已签名的请求,以及一堆其他会话内容。 My form inputs are nowhere to be found. 我的表单输入无处可寻。

The only way I can read them is to set the method of the form to "REQUEST" which isn't even a real form method. 我唯一可以读取它们的方法是将表单的方法设置为“ REQUEST”,这甚至不是真正的表单方法。 But then it takes all of my inputs and sends them as GET args in the URL. 但随后,它将接收我的所有输入,并将它们作为GET args发送到URL中。 Horrible. 可怕。 Here's a sample page from my canvas app with just a form i'm using to try to debug (leaving out all the authentication stuff): 这是我的canvas应用程序中的示例页面,仅包含我要用来调试(不包括所有身份验证内容)的表单:

<form enctype="application/x-www-form-urlencoded" method="POST" target="_top" id="my_form" action="https://apps.facebook.com/myfakeapp/form_test.php">
<input type="text" name="test1" value="58" />
<input type="text" name="test2" value="123" />
<input type="text" name="test3" value="434" />
<input type="text" name="test4" value="645" />
<input type="text" name="signed_request" value="<? echo $_REQUEST['signed_request']; ?>">
<input value="Submit Answers" type="submit">
</form>

The FB docs are confusing as some of it refers to this beta migration mode they had for older apps dealing with POST requests for canvas apps. FB文档令人困惑,因为其中一些文档涉及旧版应用程序在处理画布应用程序的POST请求时使用的这种beta迁移模式。

You are combining two separate techniques...the purpose of submitting a form with target=_top and action=apps.facebook.com/xxx is to get Facebook to automatically send the signed_request parameter. 您正在组合两种独立的技术...使用target = _top和action = apps.facebook.com / xxx提交表单的目的是让Facebook自动发送signed_request参数。 If you are sending it yourself, you should use your page's "external" address as the action and leave the target attribute off. 如果您自己发送,则应使用页面的“外部”地址作为操作,并关闭target属性。 By using target=_top, you are reloading the entire framework and sending your form data to Facebook, which of course ignores it. 通过使用target = _top,您将重新加载整个框架并将表单数据发送到Facebook,而后者当然会忽略它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM