You can't make cross-domain requests via XMLHttpRequest in
JavaScript. For the time being, you need to make the GetUploadToken
request server-side on your own server, and your JavaScript can then
access the server-side script and get back the upload token.
I'm hopeful that we'll have some support for CORS in the coming
months, which would allow you to do this directly from JavaScript, but
we don't have any specific timeline for that happening.
Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev
On Jan 1, 8:31 pm, Bo Han <bo.ning....@gmail.com> wrote:
> I've also tried to do it by just Javascript, but I get nothing in
> response:
>
> function getXMLHttpRequestObject()
> {
> var xmlhttp;
> if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
> try {
> xmlhttp = new XMLHttpRequest();
> } catch (e) {
> xmlhttp = false;
> }
> }
> return xmlhttp;}
>
> var http = new getXMLHttpRequestObject();
> var url = "http://gdata.youtube.com/action/GetUploadToken";
> var sendXML = '<?xml version="1.0"?><entry xmlns="http://www.w3.org/
> 2005/Atom"'+
> 'xmlns:media="http://search.yahoo.com/mrss/'+
> 'xmlns:yt="http://gdata.youtube.com/schemas/2007">'+
> '<media:group><media:title type="plain">Bad Wedding Toast</
> media:title>'+
> '<media:description type="plain">I gave a bad toast at my friend's
> wedding.</media:description>'+
> '<media:category scheme="http://gdata.youtube.com/schemas/2007/
> categories.cat">People</media:category>'+
> '<media:keywords>toast, wedding</media:keywords></media:group></
> entry>';
> http.open("POST", url, true);
> http.setRequestHeader("Authorization", "AuthSub
> token="+<access_token>);
> http.setRequestHeader("X-GData-Key", "key="+<dev_key>);
> http.setRequestHeader("Content-Type", "application/atom+xml;
> charset=UTF-8");
> http.setRequestHeader("Content-Length", sendXML.length);
> http.setRequestHeader("Connection", "close");
>
> http.onreadystatechange = function() {
> if(http.readyState == 4) {
> alert(http.responseXML);
> }}
>
> http.send(sendXML);
>
> On Dec 30 2011, 6:51 pm, Bo Han <bo.ning....@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I'm trying to upload the metadata for the video, but I don't quite get
> > how to make the jquery ajax call.
> > Is this part of the code correct?
>
> > $.ajax({
> > url: "http://gdata.youtube.com/action/GetUploadToken",
> > type: "POST",
> > data: {
> > Authorization: AuthSub token="<authentication_token>",
> > X-GData-Key: key=<developer_key>,
> > Content-Length: <content_length>
> > },
> > dataType: "xml"
>
> > });
>
> > How do I know what the content_length is? And how do I sent the atom
> > xml entry with the actual video information I'm about to upload?
>
> > Thanks
--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment