【问题标题】:Publish Video Facebook Using PHP SDK 4.0使用 PHP SDK 4.0 发布视频 Facebook
【发布时间】:2015-02-20 15:19:38
【问题描述】:

我正在阅读开发人员 Facebook 教程,这是他们给出的关于使用 PHP SDK 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} 中输入什么?

【问题讨论】:

    标签: php facebook video


    【解决方案1】:

    您应该可以使用 '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
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-13
        • 2012-06-19
        • 1970-01-01
        • 1970-01-01
        • 2013-11-03
        相关资源
        最近更新 更多