Upload video on fanpage via PHP API

允我心安 提交于 2019-12-12 03:57:39

问题


I have a little problem with my FB application. It's about that I always get error:

{"error":{"message":"(#353) Missing video file","type":"OAuthException","code":353}}

with this code:

            $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);

File exist, access_token is valid and is logged as a app, In $data I've tried set only 'file' or 'source' but effects was the same.


回答1:


You are best off using the Facebook PHP SDK for this, but it might be as simple as removing your file param and adding "@" to your source path. Here is a working example with the SDK (assuming you have asked for the appropriate FB permissions):

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

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


来源:https://stackoverflow.com/questions/15660817/upload-video-on-fanpage-via-php-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!