通过PHP API在fanpage上传视频

时间:2013-03-27 14:02:52

标签: php facebook opengraph

我的FB应用程序有点问题。这就是我总是得到错误:

  

{“error”:{“message”:“(#353)缺少视频文件”,“类型”:“OAuthException”,“code”:353}}

使用此代码:

            $post_url      = "https://graph-video.facebook.com/xxx/videos?"
                    . "title=" . $video_title . "&description=" . $video_desc
                    . "&access_token=" . $access_token;
            $ch = curl_init();
            $data = array(
                'source' => 'http://x/upload/' . $name . '.' . $type,
                'file' => './upload/' . $name . '.' . $type,
                'type' => 'avi',
            );
            curl_setopt($ch, CURLOPT_URL, $post_url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $response = curl_exec($ch);
            if (!$response)
            {
                print_r(Debug::vars(array(curl_error($ch), curl_errno($ch))));
            }
            curl_close($ch);

文件存在,access_token有效并记录为应用,在$data我尝试过只设置'文件'或'来源',但效果是一样的。

1 个答案:

答案 0 :(得分:0)

最好使用Facebook PHP SDK,但这可能就像删除文件参数并在源路径中添加“@”一样简单。以下是SDK的一个工作示例(假设您已经要求相应的FB权限):

$this->facebook->setFileUploadSupport(true);

$upload = $this->facebook->api('/me/videos', 'POST', array(
    'source' => '@'.$file,
    'title' => $title,
    'description' => $description
));