2013-08-05 88 views
2

使用以下命令將視頻上傳到Facebook。如果我改變curl形成後它的工作原理php - Facebook Video Upload Curl

"error":{"message":"(#353) You must select a video file to 
    upload.","type":"OAuthException","code":353}} 

$video = "http://xxx.com/video.mp4"; 
$data = array('name' => 'file', 'file' => $video, 
    'access_token' => $access_token, '_title' => $video_title, 
    'description' => $video_desc); 
$post_url = "https://graph-video.facebook.com/" . $page_id . "/videos"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $post_url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
$res = curl_exec($ch); 

我收到一個錯誤。關於爲什麼如此的任何想法?

+0

你想出了最終的解決方案? – geevee

+0

確實Facebook上傳視頻的網址? – wuliwong

回答

0

使用服務器上的視頻路徑而不是網址。所以:

$video = "uploads/video.mp4"; 

然後:繼 '@' 符號

$data = array('name' => 'file', 'file' => '@'.realpath($video), 
'access_token' => $access_token, '_title' => $video_title, 
'description' => $video_desc); 

注意使用真實路徑的()。沒有用你的代碼進行測試,但我有一個類似的實現,並且效果很好。應該做的伎倆!

0

對於FB SDK4 :(請參閱硬編碼視頻路徑和編碼)。

FB請求傳遞編碼爲表單數據的視頻文件: https://developers.facebook.com/docs/graph-api/reference/user/videos/

private function postFBVideo($authResponse, $fileObj, $formData) 
    { 
     FacebookSession::setDefaultApplication('yourAppkey', 'yourAppSecret'); 
     $ajaxResponse = ''; 
     try { 
      $session = new FacebookSession($authResponse->accessToken); 
     } catch (FacebookRequestException $ex) { 
      // When Facebook returns an error 
      $ajaxResponse = 'FB Error ->' . json_encode($ex) ; 
     } catch (\Exception $ex) { 
      // When validation fails or other local issues 
      $ajaxResponse = 'FB Validation Error - ' . json_encode($ex) ; 
     } 
     if ($session) { 
      $response = (new FacebookRequest(
       $session, 'POST', '/me/videos', array(
        'source' => new CURLFile('videos/81JZrD_IMG_4349.MOV', 'video/MOV'), 
        'message' => $formDataMessage, 
       ) 
      ))->execute(); 
      $ajaxResponse = $response->getGraphObject(); 
     } 
     return json_encode($ajaxResponse); 
    }