Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post a video using Facebook Graph API

I'm trying to post a video using Facebook Graph API from my Nodejs server with the npm package Facebook-node-sdk

Posting regular posts with message or images work fine for me, but no videos

here is my code :

var FB = require('fb');
var request = require('request');
FB.setAccessToken('MY_APP_ACCESS_TOKEN');

var params = {};
params['source'] = "@video.3gp";
params['title'] = "test video";
params['video_file_chunk'] = "@video.3gp";




FB.api('me/videos', 'post', params , function (res) {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log('Post Id: ' + res.id);
});

the video is in the same folder as my js running file.

I'm getting error code

  type: 'FacebookApiException',
  code: 390,
  error_subcode: 1363030,
like image 919
Stranger B. Avatar asked Oct 19 '22 00:10

Stranger B.


1 Answers

According to https://developers.facebook.com/docs/graph-api/video-uploads#errors the error code means

Video Upload Timeout. Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video is too large.

Also, according to https://developers.facebook.com/docs/graph-api/reference/user/videos/#Creating you need to publish your video to another Graph API endpoint:

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

POST /v2.5/{page-id}/videos HTTP/1.1
Host: graph-video.facebook.com

source=%7Bvideo-data%7D
like image 95
Tobi Avatar answered Oct 24 '22 10:10

Tobi