2013-08-05 5 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

당신이 결국 해결책을했다 않았다

FB 양식 데이터로 인코딩 전달 될 수있는 비디오 파일을 요청? – geevee

+0

URL에서 동영상을 업로드 할 때 페이스 북에서 지원 되나요? – wuliwong

답변

0

url 대신 서버에서 동영상의 경로를 사용하십시오. 그래서 그런 다음

$video = "uploads/video.mp4"; 

다음 '@'기호 다음

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

공지 사항 realpath의 사용(). 코드로 테스트하지는 않았지만 비슷한 구현이 있었고 훌륭하게 작동합니다. 속임수를 써야 해!

0

FB SDK4의 경우 (하드 코딩 된 비디오 경로 및 인코딩 참조). 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); 
    }