- Home /
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.
Does your token variable look something like this?
access_token=.....
Because this line doesn't include the access_token part:
var formurl = "https://graph-video.facebook.com/me/videos?"+ "title=" + video_title+"&description=" + video_desc + "&"+ token;
So it might look like this:
https://graph-video.facebook.com/me/videos?title=TheVideoTitle&description=VidDescription&hf7token89rf
Rather than:
https://graph-video.facebook.com/me/videos?title=TheVideoTitle&description=VidDescription&access_token=hf7token89rf
Notice the second url has the 'access_token=' part.
You might just have missed that part of the url, if you did, then you could use this ins$$anonymous$$d:
var formurl = "https://graph-video.facebook.com/me/videos?"+ "title=" + video_title+"&description=" + video_desc + "&access_token="+ token;
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.
Answer by ddfire · Sep 20, 2013 at 10:30 AM
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 ∾cess_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.