www form 400 bad request

I’m trying to upload a video to facebook using the following code. The token and login are provided by a plugin. The overall url returns 400 bad request from facebook. The url is almost exactly what it would be if given from php. Am I doing something wrong in using www?

https://graph-video.facebook.com/me/videos?title=dogwalk&description=walkingthedog&access_token=BAABwFmwNiEIBAIGTyeitkr8SiA3CTUGFa46wFs8k87b1SC31Fi8loH4i8eZBoF561MAKJtwdIf8KVWbUYrroQirkFA7mjC1VAB7Ji6ujtphH81uZCPMqWaRpQWtvGoBiMwEseoGAPgMFqhwVhoTqTkrz56fPTK54t2FdN5X3kohTCZBqKL1odJ1H5Ip0bP8hAgvMdmRFvtc14UsnBIXr9CW9LPzjB7MxkQzOFyfiQZDZD
private WWW w;
public void FBPostVideo(){
var moviebytes = System.IO.File.ReadAllBytes(Application.persistentDataPath+"/screenrecording.mp4");
Debug.Log(moviebytes.Length);
WWWForm form = new WWWForm();
Hashtable myheaders = new Hashtable();
myheaders.Add("enctype","multipart/form-data");
var video_desc="walkingthedog";
var video_title="dogwalk";
var access_token=token;
form.AddBinaryData("file", moviebytes, "myvideo");
Debug.Log("the token="+token);
//var formurl="https://graph-video.facebook.com/";
var formurl = "https://graph-video.facebook.com/me/videos?"+ "title=" + video_title+"&description=" + video_desc + "&"+ token;
Debug.Log(formurl);
WWW w = new WWW(formurl,form.data,myheaders);
StartCoroutine(waitForMovie(w));
}

I tried to post an image using almost exactly the same code and it works fine.

Hi. Thanks for taking a stab at it. I've tried it both ways since posting and it gives the same 400 bad request. I've also tried putting the token in the form and same result. I've also since successfully uploaded an image using almost the same code structure. So I'm stumped.

1 Answer

1

Hi
Your problem is in the WWWForm add one more parameter to form.AddBinaryData the last one should be “multipart/form-data” and also add the &access_token=
Be sure you have the permissions to post…

i have this working in C# and it is like this

   public IEnumerator startUpload(string pathToFile,string title,string token,string Description){
       string URL ="https://graph-video.facebook.com/me/videos";
       WWWForm wf = new WWWForm();
       StringBuilder sb = new StringBuilder();
       sb.Append(URL);
       sb.Append("?title=");
       sb.Append(title);
       sb.Append("&description=");
       sb.Append(Description);
       sb.Append("&access_token=");
       sb.Append(token);
       wf.AddBinaryData("file",File.ReadAllBytes(pathToFile),"FileName.mkv","multipart/form-data");
        		
       Debug.Log("VIDEO POST URL: " + sb.ToString());
       www = new WWW(sb.ToString(),wf);
       yield return www;
       Debug.Log("WWW.ERROR: " + www.error);
       Debug.Log("WWW.TEXT: " + www.text);
   }

Cool. Thanks. I don't think I would have ever figured that out.