Upload video to Facebook, with RestFB

3.2k Views Asked by At

I'm trying to upload video with RestFB, I tried do this for 2 days, but still can't do it, can somebody help me with this? What I've done.

I know that I can upload video with this method video.upload, and I must send request to the Facebook video server, so I create class VideoLegacyFacebookClient, and put there this server, also I tried make new execute method, which take a InputStream binaryAttachement for video, and try to make this code:

InputStream is=new DataInputStream(new FileInputStream(new File("/home/hagen/testing.avi")));
postId = facebookClient.execute("video.upload", null, String.class,is,
                    Parameter.with("title", "My Test Video"),
                    Parameter.with("description", "This is description"));

What did I do wrong, can someone help me?

4

There are 4 best solutions below

0
On

RestFB 1.6.5 may fix this problem; http://restfb.googlecode.com/svn/tags/restfb-project-1.6.5/CHANGELOG says:

Added support for the new video upload API endpoint via https://graph-video.facebook.com and fixed a multipart filename bug that broke video uploads.

0
On

Facebook How-tos about video upload may be useful https://developers.facebook.com/blog/post/493/

1
On
DataInputStream is =new DataInputStream(
new FileInputStream(new File("C:\\Users\\samiii\\Desktop\\rock.mp4")));
                fbClient.publish("me/videos", FacebookType.class,
                BinaryAttachment.with("rock.mp4", is),
                Parameter.with("title", "rock"),
                Parameter.with("description", "my first vid"));

Try this one, it work 100%

0
On

Below Snippet will work with valid app access token, app secret,

Note: kept videos under resources/videos folder.

Uploading to a Page:

DefaultFacebookClient facebookClient = new DefaultFacebookClient(accessToken, appSecret, Version.LATEST);
facebookClient.publish(fbPageID + "/videos", GraphResponse.class, BinaryAttachment.with("videoName.mp4", IOUtils.toByteArray(getClass().getResourceAsStream("/video/videoName.mp4"))),
                    Parameter.with("description", " Video Description "));