您可能知道,为了传递用户的信息(signed_request
)
到您的应用程序,Facebook访问画布(即:iframe)应用程序
向他们发送POST
请求。解释了这种机制here。
为了保持ReSTful,Symfony中最合适的地方(哪个服务, file ...)实现Ruby on Rails的技巧Pierre Olivier Martel descibes:http://blog.coderubik.com/2011/03/restful-facebook-canvas-app-with-ra ... ,例如:转换包含'signed_request'的每个POST请求 参数GET一个?
答案 0 :(得分:2)
您可以像在RESTBundle中一样实现RequestListener:https://github.com/FriendsOfSymfony/RestBundle/blob/master/EventListener/RequestListener.php
答案 1 :(得分:2)
灵感来自Stuck's answer(谢谢!)和Symfony Cookbook:
# src/Acme/FacebookBundle/RequestListener.php
namespace Acme\FacebookBundle;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class RequestListener
{
public function onCoreRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if ('POST' == $request->getMethod() && null !== $request->get('signed_request'))
{
$request->setMethod('GET');
}
}
}
服务定义:
# app/config/config.yml
services:
acme.facebookbundle.listener.request:
class: Acme\FacebookBundle\RequestListener
tags:
- { name: kernel.listener, event: core.request, method: onCoreRequest }