开发者

Facebook Graph API - Video Upload

开发者 https://www.devze.com 2023-02-11 09:15 出处:网络
With the REST api in the process of being deprecated, I\'m trying to convert our existing application to use the facebook c# sdk.

With the REST api in the process of being deprecated, I'm trying to convert our existing application to use the facebook c# sdk.

One of the things we can currently do, is post a video by uploading it.

I've created a POST request as follows, but I'm getting a failure of 'Unsupported Post Request'.

            byt开发者_开发百科e[] video = File.ReadAllBytes(TESTDATA_DIR + "Snowboarding penguin.mov");

        if (_FBClient != null)
        {
            var parameters = new Dictionary<string, object>();
            parameters.Add("message", "This is a Graph API unit test message containing a video! (" + DateTime.Now.ToString() + ")");
            parameters["caption"] = "This is the caption for the unit test message!";
            parameters["description"] = "This is description for the unit test message!";
            parameters["name"] = "This is name of the unit test message!";
            parameters["req_perms"] = "publish_stream";
            parameters["scope"] = "publish_stream";

            var mediaObject = new FacebookMediaObject
            {
                FileName = "Snowboarding penguin.mov",
                ContentType = "video/mov",
            };
            mediaObject.SetValue(video);
            parameters.Add("source", mediaObject);

            _FBClient.Post("me/videos", parameters);
        }

I see lots of general posts about video uploading not being supported by the GRAPH API, but hopefully this has been resolved by FB now.

Can anyone steer me in the right direction for getting this request to work?

TIA


Video uploading is not supported by the graph api. You will need to use the old rest api.

        var videoPath = "c:\\sample.3gp";
        byte[] video = File.ReadAllBytes(videoPath);

        var mediaObject = new FacebookMediaObject
                              {
                                  FileName = "sample.3gp",
                                  ContentType = "video/3gpp"
                              };
        mediaObject.SetValue(video);

        dynamic parameters = new ExpandoObject();
        parameters.source = mediaObject;
        parameters.method = "video.upload";
        parameters.access_token = "access_token";

        var fb = new FacebookClient();
        dynamic result = fb.Post(parameters);

UPDATE Facebook recently supported uploading video via graph api. You can find the details on how to use graph api video upload from Facebook C# SDK at http://blog.prabir.me/post/Facebook-CSharp-SDK-Uploading-Video-via-Graph-Api.aspx

Requires Facebook C# SDK v5.0.46 or higher.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号