开发者

Posting to YouTube API with jQuery

I am trying to post a request to the google authSub for youtube. I use jQuery for AJAX posts etc. When I make the POST I get a 405 error: "405 Method Not Allowed".

Here i开发者_开发技巧s my js:

   $.ajax({
      type: 'POST',
      url: "https://www.google.com/accounts/AuthSubRequest",
      beforeSend: function(xhr){
         xhr.setRequestHeader('X-GData-Key', 'key="' + ytKey + '"');
      },
      success: function(oData){
         //alert(oData);
      },
      scope: 'http://gdata.youtube.com',
      alt: 'json',
      next: 'http://' + globalBrand + '/sitecreator/view.do',
      session: 1
   });

The page I am using in the API for this is here.

Here is what the error looks like:

Posting to YouTube API with jQuery


Your data parameters for the request are misplaced see below:

$.ajax({
      type: 'POST',
      url: "https://www.google.com/accounts/AuthSubRequest",
      data: {
        scope: 'http://gdata.youtube.com',
        alt: 'json',
        next: 'http://' + globalBrand + '/sitecreator/view.do',
        session: 1
      },
      beforeSend: function(xhr){
         xhr.setRequestHeader('X-GData-Key', 'key="' + ytKey + '"');
      },
      success: function(oData){
         //alert(oData);
      }

   });

Now it may be something youre doing wrong additionally, but this for sure needs to be corrected.


Ah, here is a solution to the problem. If I make the request with the url built out and assigned as an href to an anchor or call it in window.open(); it works.

window.open('https://www.google.com/accounts/AuthSubRequest?scope=http://gdata.youtube.com&next=http://' + globalBrand + '/sitecreator/view.do&session=1');

As for why jQuery's method with the ajax was being rejected I know not. It seems to be an issue elsewhere also.


Solution to error HTTP HEADER OPTIONS in JQuery, this request is ok for me:

var word = 'search+word';
$.ajax({
        type: "GET",
        url: "http://gdata.youtube.com/feeds/api/videos?q="+word+"&max-results=10&alt=json-in-script&format=5,
        cache: false,
        dataType:'jsonp',
        success: function(data){
                //json 'data' var treatment
        },
       error: function(XMLHttpRequest, textStatus, errorThrown, data){
            alert("Not able to fetch the data due to feed unavailability!!!");
        }
});

Reference: http://www.mohammedarif.com/?p=180

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜