2013-05-21 186 views
0

在我之前提出的問題How to upload video in vimeo account through vimeo api in Symfony 2.2現已關閉。現在我有,我想通過我的應用程序與VIMEO API幫助到我使用的如何通過Vimeo api從Vimeo帳戶中刪除視頻

「vimeo.videos.delete」方法 下面

給出刪除還有Vimeo帳戶上傳的視頻多了一個要求
/** 
* 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

請不要通過編輯它來解答你的問題,並把標題中的(解決)。 Insted發表一個答案並接受它。 Thx – 0x1gene

回答

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; 
} 
+1

您現在可以通過[點擊選中標記]接受你的回答(http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。 – Antony