oEmbed在Symfony 3实现中

oEmbed在Symfony 3实现中,symfony,oembed,Symfony,Oembed,我想允许用户在我的网站上创建内容。 有很多关于如何实现它的信息,但没有关于创建enpoint的信息 快速提问:是否有一些现成的php代码示例,用于为第三方网站创建(返回)oEmbed响应 如果没有,如何创建它?Ex youtube链接如下所示: 答复是: { "html": "<iframe width=\"459\" height=\"344\" src=\"https://www.youtube.com/embed/iwGFalTRHDA?feature=oembed\" f

我想允许用户在我的网站上创建内容。 有很多关于如何实现它的信息,但没有关于创建enpoint的信息

  • 快速提问:是否有一些现成的php代码示例,用于为第三方网站创建
    (返回)oEmbed响应

  • 如果没有,如何创建它?Ex youtube链接如下所示:

    答复是:

    {
        "html": "<iframe width=\"459\" height=\"344\" src=\"https://www.youtube.com/embed/iwGFalTRHDA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
        "thumbnail_height": 360,
        "thumbnail_width": 480,
        "provider_name": "YouTube",
        "author_url": "https://www.youtube.com/user/KamoKatt",
        "thumbnail_url": "https://i.ytimg.com/vi/iwGFalTRHDA/hqdefault.jpg",
        "author_name": "KamoKatt",
        "provider_url": "https://www.youtube.com/",
        "type": "video",
        "version": "1.0",
        "width": 459,
        "title": "Trololo",
        "height": 344
    }
    
    {
    “html”:“,
    “缩略图高度”:360,
    “缩略图宽度”:480,
    “提供商名称”:“YouTube”,
    “作者url”:https://www.youtube.com/user/KamoKatt",
    “缩略图url”:https://i.ytimg.com/vi/iwGFalTRHDA/hqdefault.jpg",
    “作者姓名”:“KamoKatt”,
    “提供程序url”:https://www.youtube.com/",
    “类型”:“视频”,
    “版本”:“1.0”,
    “宽度”:459,
    “标题”:“特罗洛洛”,
    “高度”:344
    }
    
    我的问题是:他们怎么知道这是哪个视频?他们正在使用regexp解析
    videoID

  • 这种请求的“最佳实践”是什么?它应该被创建为控制器、服务、提供者还是如何创建


  • 最后,我创建了如下内容:

  • 我创建了一个服务:
  • 服务.yml

    app.embed:
        class: AppBundle\Service\EmbedService
        arguments: ["%base_url%", "@doctrine.orm.entity_manager", "@twig"]
    
    参数.yml

    base_url: "http://project.local"
    
    控制器中的下一步:

    /**
     * @Route("/oembed.{_format}",
     *     name="embed",
     *     defaults={"_format": null}
     * )
     * @param Request $request
     * @param $_format
     * @return \Symfony\Component\HttpFoundation\Response
     * @throws \Exception
     */
    public function generateAction(Request $request, $_format)
    {
    
        $oEmbed = $this->get('app.embed');
        $oEmbed->handleRequest($request, $_format);
    
        $view = View::create()
            ->setFormat($oEmbed->getFormat())
            ->setStatusCode(200)
            ->setData($oEmbed->create());
    
        return $this->handleView($view);
    }
    
    你这样称呼它:

    /**
     * @Route("/oembed.{_format}",
     *     name="embed",
     *     defaults={"_format": null}
     * )
     * @param Request $request
     * @param $_format
     * @return \Symfony\Component\HttpFoundation\Response
     * @throws \Exception
     */
    public function generateAction(Request $request, $_format)
    {
    
        $oEmbed = $this->get('app.embed');
        $oEmbed->handleRequest($request, $_format);
    
        $view = View::create()
            ->setFormat($oEmbed->getFormat())
            ->setStatusCode(200)
            ->setData($oEmbed->create());
    
        return $this->handleView($view);
    }