Restful Facebook画布Symfony2应用程序

时间:2011-06-10 19:25:17

标签: facebook rest symfony

您可能知道,为了传递用户的信息(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一个

2 个答案:

答案 0 :(得分:2)

答案 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 }