Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I'm trying to upload an Ad Video to facebook using the steps given in below url and Facebook SDK for Dot.NET.

https://developers.facebook.com/docs/marketing-api/advideo/v3.2[^]

My Code:

var fbClient = GetFB();
                FileStream fs = new FileStream("E:\\cnp.mp4",
                                   FileMode.Open,
                                   FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);

                dynamic parameters = new System.Dynamic.ExpandoObject();
                parameters.upload_phase = "start";
                Console.WriteLine("file_size: {0}", fs.Length);
                parameters.file_size = fs.Length;
                dynamic result = fbClient.Post("/" + FBAccountID + "/advideos", parameters);
                Console.WriteLine("upload_session_id: {0}", (string)result["upload_session_id"]);
                string upload_session_id = (string)result["upload_session_id"];
                Console.WriteLine("Video Id: {0}", (string)result["video_id"]);
                Console.WriteLine("start_offset: {0}", (string)result["start_offset"]);
                Console.WriteLine("end_offset: {0}", (string)result["end_offset"]);

                int startOffset = 0;
                int endOffset = int.Parse((string)result["end_offset"]);

                while (endOffset > startOffset)
                {
                    byte[] buff = new byte[endOffset - startOffset];
                    buff = br.ReadBytes((endOffset - startOffset));

                    dynamic transfer = new System.Dynamic.ExpandoObject();
                    transfer.upload_phase = "transfer";
                    transfer.upload_session_id = upload_session_id;
                    transfer.start_offset = startOffset;
                    transfer.video_file_chunk = buff;
                    //--Getting Error

                    dynamic TransferResult = fbClient.Post("/" + FBAccountID + "/advideos", transfer);
                    Console.WriteLine("start_offset: {0}", (string)TransferResult["start_offset"]);
                    Console.WriteLine("end_offset: {0}", (string)TransferResult["end_offset"]);
                    startOffset = int.Parse((string)TransferResult["end_offset"]);
                    endOffset = int.Parse((string)TransferResult["end_offset"]);
                }

                dynamic finish = new System.Dynamic.ExpandoObject();
                finish.upload_phase = "finish";
                finish.upload_session_id = upload_session_id;
                finish.title = "Video title";
                dynamic result2 = fbClient.Post("/" + FBAccountID + "/advideos", finish);
                Console.WriteLine("success: {0}", (string)result2["success"]);
                if ((string)result2["success"] == "true")
                {

                }


The First request for Start was successful and we are getting the VideoID and Upload SessionID, and the second request is failing with error


Facebook.FacebookOAuthException: '(OAuthException - #2) Service temporarily unavailable'

Error User Title: "Video Upload Time Out"

Error User Message: "Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video you're trying to upload is too large. Please try again."

Facebook.FacebookOAuthException occurred
HResult=0x80131500
Message=(OAuthException - #2) Service temporarily unavailable
Source=Facebook
StackTrace:
at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)
at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType)
at Facebook.FacebookClient.Post(String path, Object parameters)
at WebApplication1._Default.Facebook() in C:\Users\suneel.CLICKANDPLEDGE\documents\visual studio 2017\Projects\TestConsoleApp\WebApplication1\Default.aspx.cs:line 132
at WebApplication1._Default.Page_Load(Object sender, EventArgs e) in C:\Users\suneel.CLICKANDPLEDGE\documents\visual studio 2017\Projects\TestConsoleApp\WebApplication1\Default.aspx.cs:line 16


What I have tried:

I'm passing the byte[] to video_file_chunk. As per the documentation it says binary file.

I tried manipulating
video_file_chunk
but getting the same error,

Thanks in advance for any help.
Posted
Updated 27-Dec-18 23:58pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900