使用PHP SDK 4.0发布视频Facebook [英] Publish Video Facebook Using PHP SDK 4.0

查看:56
本文介绍了使用PHP SDK 4.0发布视频Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读开发人员Facebook教程,这是他们对使用PHP SDK 4.0发布视频的解释:

 /* PHP SDK v4.0.0 *//*进行API调用*/$ request =新的FacebookRequest($ session,'邮政',"/{page-id}/视频",大批 ('源'=>"{video-data}",));$ response = $ request-> execute();$ graphObject = $ response-> getGraphObject();/*处理结果*/ 

他们还解释说:视频必须编码为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}中输入什么?

解决方案

解决了问题:

 //获取当前用户的GraphUser对象:尝试 {$ response =(新的FacebookRequest($ session,'邮政','/page_id/videos',大批 ('description'=>'测试','源'=>新的CURLFile('path/to/file/video.wmv','video/wmv'),)))-> execute()-> getGraphObject();回声张贴与ID:".$ response-> getProperty('id');} catch(FacebookRequestException $ e){echo发生异常,代码:".$ e-> getCode();回显带有消息:".$ e-> getMessage();} catch(\ Exception $ e){//发生其他错误} 

I am reading the developers Facebook tutorial, and this is the explanation they give about publishing videos using 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 */

They also explain that "Videos must be encoded as multipart/form-data and published to graph-video.facebook.com instead of the regular Graph API URL."

I have the video in my server (http://www.example.com/videos/video.mp4) or in a folder in my application directory (.../videos/video.mp4), and don't know how to "use" it in this example of the PHP SDK 4.0.

I saw some exemples using a form to post the video, but I want to do it automatically, without the need to choose manually the file to upload.

Anyone know to publish the video that I have in my server, using the PHP SDK? What should I put in the {video-data} in the "source" field?

解决方案

Solved the problem:

// 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
}

这篇关于使用PHP SDK 4.0发布视频Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆