在 Facebook 画布应用程序中访问 POST 数据
我的 canvas / iframe Facebook 应用程序中有一个简单的表单,我正在尝试将值作为 POST 传递。现在,根据我的理解,通过阅读 SO 和 FB 的最新文档,所有通过 POST 表单发送的数据都可以在接收端从 $_REQUEST 对象访问。
我还在另一个线程上读到,为了使 POST 表单正常工作,您需要传递一个名为“signed_request”的输入,其值为当前的signed_request(我的签名请求工作正常,否则...所有登录和身份验证东西工作正常)。官方 FB 文档中没有提到这一点。
所以我的问题是 $_REQUEST 对象中返回的只是签名的请求,以及一堆其他会话内容。我的表单输入无处可寻。
我可以阅读它们的唯一方法是将表单的方法设置为“REQUEST”,这甚至不是真正的表单方法。但随后它会获取我的所有输入并将它们作为 URL 中的 GET args 发送。可怕。这是我的画布应用程序中的一个示例页面,其中只有一个我用来尝试调试的表单(省略了所有身份验证内容):
<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>
FB 文档令人困惑,因为其中一些引用了他们为旧应用程序处理的测试版迁移模式与画布应用程序的 POST 请求。
I've got a simple form in my canvas / iframe Facebook app, and I'm trying to pass along the values as POST. Now from reading all about this all over S.O. 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.
I also read on another thread on S.O. 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). This isnt mentioned anywhere in the official FB docs.
So my problem is that all that comes back in the $_REQUEST object is the signed request, and a bunch of other session stuff. 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. But then it takes all of my inputs and sends them as GET args in the 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):
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在结合两种不同的技术...提交带有 target=_top 和 action=apps.facebook.com/xxx 的表单的目的是让 Facebook 自动发送signed_request 参数。如果您自己发送,则应使用页面的“外部”地址作为操作,并关闭目标属性。通过使用 target=_top,您将重新加载整个框架并将表单数据发送到 Facebook,当然 Facebook 会忽略它。
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. If you are sending it yourself, you should use your page's "external" address as the action and leave the target attribute off. By using target=_top, you are reloading the entire framework and sending your form data to Facebook, which of course ignores it.