- Home /
use unity wwwform to upload youtube video?
How would I upload a video to youtube using wwwform?
I'm reading the docs but don't understand their php example and how I would translate this to unity. They also have a .net guide but it's custom .net api.
Can't I do this straight from unity without using php or .net?
https://developers.google.com/youtube/2.0/developers_guide_dotnet
something like
var form = new WWWForm();
form.AddField("frameCount", Time.frameCount.ToString());
form.AddBinaryData("fieldname", bytes, "video.mov", "video/quicktime");
var w = WWW("some url", form);
yield w;
if (w.error != null)
print(w.error);
else
print("Finished Uploading Screenshot");
}
Answer by ByteSheep · Mar 28, 2012 at 12:24 AM
Nearly certain you have to use php and that you can't do this directly through unity..
php files can receive data from unity using the get() function, so you can send variables to the php file (e.g. video name & location) and then use php to upload that file/video to youtube.
Haven't got too much experience with the unity WWW class but I'll give it a go:
var postTo="yourURL/file.php?"; //be sure to add a ? to your url
var videolocation="video location";
function Start() {
var TheURL = postTo + "loc=" + WWW.EscapeURL(videolocation);
// Post the URL to the site
video_post = WWW(TheURL);
yield video_post;
if(video_post.error) {
print("There was an error: " + video_post.error);
}
}
Then use the get() function in the php file:
if($_GET['loc'])
{
$vidlocation = $_GET['loc'];
//now you have the location of the video that should be uploaded..
}
Hope this helped :D
Answer by DaveA · Mar 28, 2012 at 02:16 AM
You would have to be NOT using a web player so you could read the local file (or you have already converted some in-game memory to a compatible format), and you need to specify the bytes to upload. If going direcly to youtube you might need to figure out if they have special header info, like your login credentials etc. that should be attached to the headers. So while a php proxy as merry_christmas suggests would work, you still need to figure out what youtube needs and get the bytes of the content on that form.