0

在我之前提出的问题中,如何通过 Symfony 2.2 中的 vimeo api 在 vi​​meo 帐户中上传视频, 现在已关闭。现在我还有一个要求,我想通过我的应用程序在我使用的 vimeo api 的帮助下从 vimeo 帐户中删除上传的视频

“vimeo.videos.delete”方法如下

/**
 * Deletes a Video entity.
 *
 * @Route("/{id}", name="video_delete")
 * @Method("DELETE")
 * @Secure(roles="ROLE_SUPER_ADMIN")
 */
public function deleteAction(Request $request, $id)
{
    $vimeo = new phpVimeo('my_api_key', 'my_api_key_secret', 'my_token', 'my_token_secret');
    $form = $this->createDeleteForm($id);
    $form->bind($request);
    $em = $this->getDoctrine()->getManager();
    $video = $em->getRepository('MyBundle:Video')->find($id);

        if (!$video) {
            throw $this->createNotFoundException('Unable to find Video entity.');
        }
    $videoId = $video->getVideoId();

    if ($form->isValid()) {
        try
        {
        $vimeo->call('vimeo.videos.delete',array('video_id',$videoId));
        $em->remove($video);
        $em->flush();
    }
    catch (VimeoAPIException $e) {
            echo "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
        }
    }

    return $this->redirect($this->generateUrl('video'));
    }
}

但是,当我尝试在我的应用程序中删除选定的视频时,它会尝试删除视频,但无法从 vimeo 帐户中删除视频,而从我的数据库中删除了该视频的参考信息,而我想从两者中删除视频数据库和 vimeo 帐户。我不知道我在做什么错?

如果任何人都可以获得有关此问题的任何帮助,请帮助我解决此问题。

4

1 回答 1

0

现在通过对我的编码进行一些更改,我已经解决了!

/**
 * Deletes a Video entity.
 *
 * @Route("/{id}", name="video_delete")
 * @Method("DELETE")
 * @Secure(roles="ROLE_SUPER_ADMIN")
 */
public function deleteAction(Request $request, $id)
{
    $form = $this->createDeleteForm($id);
    $form->bind($request);
    $em = $this->getDoctrine()->getManager();
    $video = $em->getRepository('MyBundle:Video')->find($id);

        if (!$video) {
            throw $this->createNotFoundException('Unable to find Video entity.');
        }
    $videoId = $entity->getVideoId();

    if ($form->isValid()) {
        try
        {
        $api = $this->api();

        $method = 'vimeo.videos.delete';

        $query = array();
        $query['video_id'] = $videoId;

        $r = $api->call($method, $query);

    }
    catch (VimeoAPIException $e) {
            echo "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
        }
        $em->remove($video);
        $em->flush();
    }

    return $this->redirect($this->generateUrl('video',array('result'=> $r)));
    }

 public function api()
{
    $consumer_key = 'my_api_key';
    $consumer_secret = 'my_api_key_secret';

    $token = 'my_access_token';
    $token_secret = 'my_access_token_secret';

    $vimeo = new phpVimeo($consumer_key, $consumer_secret);
    $vimeo->setToken($token, $token_secret);

    return $vimeo;
}
于 2013-06-13T10:57:29.813 回答