Thursday, January 6, 2022

[FIXED] How to upload video and thumbnail to facebook together using PHP SDK?

Issue

I want upload video and thumbnail of the video together to Facebook using default facebook sdk.

Please help me to continue work.

Thank you.


Solution

    $fb = new Facebook\Facebook([
            'app_id' => FB_APP_ID,
            'app_secret' => FB_APP_SECRET,
            'default_graph_version' => 'v2.8',
        ]);

        //add parameter to scheduled_publish_time
        $data = [
            'title' => $vid_name,
            'message' => $vid_desc,
            'source' => $fb->fileToUpload(VIDEO_PATH.$vid_id."/".$video['vid_filename']),
        ];
//$thumbfile is thumbnail path.
        if(!empty($thumbfile)){`enter code here`
            $data['thumb'] = imagecreatefromstring(file_get_contents($thumbfile));
        }
    $response = $fb->post('/me/videos', $data, $token);


Answered By - Angel

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.