views:

56

answers:

2

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 is 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: alt text

+1  A: 

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.

prodigitalson
Ah, wow, can't believe I missed that one. However, I still get the 405 error.
Dale
what are you trying to do with `alt: 'json'` i dont see that in the API link you posted. Also looks like youre missing a header for `Authorization: AuthSub token="<authentication_token>"`
prodigitalson
I just added that for memory purposes for other requests I will be making. I commented it out now and I still get the 405.
Dale
What does the request look like in firebug... You should be bale to check that the headers are correct and the data is encoded properly.
prodigitalson
I added an image to my original question of firebug with the 405 error with the headers.
Dale
This request it to get the authentication token. I do not have it yet.
Dale
Try Removing the header you added for you gdata key. I think you only use that after you have the token.
prodigitalson
Good idea but still doesn't work. Same error.
Dale
A: 

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&amp;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.

Dale