在我之前提出的问题How to upload video in vimeo account through vimeo api in Symfony 2.2中,它现在已经关闭。现在,我还有一个要求,就是我想通过我的应用程序在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帐户中删除视频。我不知道我做错了什么?
如果任何人在这个问题上有任何帮助,请帮助我解决这个问题。
发布于 2013-06-13 10:57:29
现在,通过我的编码的一点点改变,我已经解决了它!
/**
* 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;
}https://stackoverflow.com/questions/16661900
复制相似问题