2014-12-22 55 views
2

我讀開發商Facebook的教程,這是他們給有關使用PHP SDK 4.0發佈影片的解釋:發佈視頻Facebook 4.0

/* PHP SDK v4.0.0 */ 
/* make the API call */ 
$request = new FacebookRequest(
    $session, 
    'POST', 
    '/{page-id}/videos', 
    array (
    'source' => '{video-data}', 
) 
); 
$response = $request->execute(); 
$graphObject = $response->getGraphObject(); 
/* handle the result */ 

他們還解釋說,「影片必須被編碼爲multipart/form-data併發布到graph-video.facebook.com,而不是定期的Graph API URL。「

我在我的服務器(http://www.example.com/videos/video.mp4)或我的應用程序目錄(.../videos/video.mp4)中的文件夾中有視頻,並且不知道如何在此示例中「使用」它PHP SDK 4.0。

我看到一些使用表單發佈視頻的例子,但我想自動完成,而無需手動選擇要上傳的文件。

任何人都知道使用PHP SDK發佈我的服務器中的視頻?我應該在「源」字段中放入{video-data}?

回答

0

您應該可以使用'source' => '@/path/to/file',因爲它是cURL的包裝。

請注意,如果這是一個大文件,它可能會更好地做到這一點作爲後臺進程 - 如果文件需要一兩分鐘從服務器上傳用戶將坐在那裏想知道是否有什麼不工作對。

2

問題解決了:

// Get the GraphUser object for the current user: 
try { 
    $response = (new FacebookRequest(
    $session, 
    'POST', 
    '/page_id/videos', 
    array (
    'description' => 'test', 
    'source' => new CURLFile('path/to/file/video.wmv', 'video/wmv'), 
    ) 
))->execute()->getGraphObject(); 

    echo "Posted with id: " . $response->getProperty('id'); 

} catch (FacebookRequestException $e) { 
    echo "Exception occured, code: " . $e->getCode(); 
    echo " with message: " . $e->getMessage(); 
} catch (\Exception $e) { 
    // Some other error occurred 
}