Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dansav · Apr 26, 2013 at 07:24 AM · wwwwwwform

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));
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dansav · Apr 27, 2013 at 01:59 AM 0
Share

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

avatar image ByteSheep · Apr 27, 2013 at 02:23 AM 0
Share

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;
avatar image dansav · Apr 27, 2013 at 02:29 AM 0
Share

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 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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);
    }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dansav · Sep 20, 2013 at 05:45 PM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting info using WWW & PHP 3 Answers

How do I make a simple POST request to Amazon S3? 2 Answers

WWW/WWWForm, does Unity validate SSL certificates? 1 Answer

How to Upload multiple files to a server using UnityWebRequest.Post(); 3 Answers

How to use POST service using www class? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges