Stranger B.
Stranger B.

Reputation: 9364

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,

Upvotes: 5

Views: 4042

Answers (2)

Stranger B.
Stranger B.

Reputation: 9364

I used a the graph REST API to Upload a video to Facebook from parse :

Parse.Cloud.httpRequest({
        method: 'POST',
        url: 'https://graph.facebook.com/v2.5/{page_id}/videos?access_token='+token+'&message='+message+'&file_url='+image,
        success: function(httpResponse) {
            console.log(httpResponse.data);
            response.success("result");
        },
        error:function(httpResponse){
            //console.log("Not logging this");
            console.error(httpResponse.message);
            response.error("Failed to login");
        }
    });

Upvotes: 1

Tobi
Tobi

Reputation: 31479

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

Upvotes: 2

Related Questions