Facebook C# SDK - Uploading Video via Graph Api

(This feature requires Facebook C# SDK v5.0.45 at minimum.)

Recently Facebook supported uploading videos via graph api which was detailed in this blog post. Unlike other graph api, uploading video requires a change in the root url. Instead of pointing to “https://graph.facebook.com” it needs to point to “https://graph-video.facebook.com”.

So how do I tell the SDK to use https://graph-video.facebook.com?

The SDK is smart enough in figuring it out. Here is the code that uses https://graph-video.facebook.com to upload video.

var fb = new FacebookClient("access_token");

dynamic parameters = new ExpandoObject();
parameters.source = new FacebookMediaObject { ContentType = "video/3gpp", FileName = "video.3gp" }.SetValue(File.ReadAllBytes(@"c:\video.3gp"));
parameters.title = "video title";
parameters.description = "video description";

dynamic result = fb.Post("/me/videos", parameters);
Console.WriteLine(result);

How does it work internally?

First of all to use graph-video you need to do a http post using Post or PostAsync methods. Then the sdk checks your path. If the path ends in “/videos” it then uses graph-video sub-domain instead of graph sub-domain.