OAuth2.0 Error : 405 Method Not allowed.

8,100 views
Skip to first unread message

Gauri B

unread,
Jun 2, 2012, 5:04:45 AM6/2/12
to oauth...@googlegroups.com
Hi All,
 
      I am facing one problem to get the access token for you tube api using oAuth2.0. I got the "code" parameter. But when I tried to exchange the "code" parameter for access token it's throwing an error 405, Method not allowed.

 Even the simple http request for access token without any parameters "https://accounts.google.com/o/oauth2" throwing the same error.

 Here is my sample code:

$.ajax({
method: 'POST',
                contentType: 'application/x-www-form-urlencoded',
data : {
code : '4/MPH9vS5QCvJs9PB_b_tw5n3Avpvs.0vEfS-A70z4TgrKXntQAax0EzVBNbwI',
client_secret : 'kiuSP80klPiYCB-xN8vYPi0R',
grant_type : 'authorization_code'
},
success :function(data){
var jsonObj = jQuery.parseJSON(data); 
alert( jsonObj);
}
});


        here I am getting jsonObj  as null. 
        Please let me know If there is anything wrong with the above code.  Any help would be appreciated.
          
        Thanks in advance.

        Regards,
          Gauri

Marius Scurtescu

unread,
Jun 2, 2012, 11:24:45 PM6/2/12
to oauth...@googlegroups.com
Hi Gauri,

Your are getting the 405 error most likely because your code is not
sending an HTTP POST request.

https://accounts.google.com/o/oauth2 is not an endpoint, we you are
trying to access that you get a 404 error (and not 405).

Marius
> --
> You received this message because you are subscribed to the Google Groups
> "oauth2-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/oauth2-dev/-/d2qtKgi0eCcJ.
> To post to this group, send email to oauth...@googlegroups.com.
> To unsubscribe from this group, send email to
> oauth2-dev+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/oauth2-dev?hl=en.

Gauri B

unread,
Jun 4, 2012, 3:49:07 AM6/4/12
to oauth...@googlegroups.com
Hi Marius,
 
       Thanks for your reply. But I am still stuck with the same error 405 : method not allowed.
       I am not getting why my code is not sending HTTP POST request. Is anything wrong with my code? OR Am I missing something?

       I am doing this for server side web applications using Java.  

       According to https://developers.google.com/youtube/2.0/developers_guide_protocol I am trying to POST request to  "https://accounts.google.com/o/oauth2/token" but this itself gives the error : method not allowed.

       what is wrong here?  Please guide me.

       Thanks in advance.

      Regards,
        Gauri 
 
        

On Sunday, June 3, 2012 8:54:45 AM UTC+5:30, Marius Scurtescu wrote:
Hi Gauri,

Your are getting the 405 error most likely because your code is not
sending an HTTP POST request. Is anything wrong with my code? OR Am I missing something? 
 
> For more options, visit this group at
> http://groups.google.com/group/oauth2-dev?hl=en.
> oauth2-dev+unsubscribe@googlegroups.com.

Gauri B

unread,
Jun 4, 2012, 10:16:51 AM6/4/12
to oauth...@googlegroups.com

  My code is sending HTTP POST request successfully that means I get status 200 OK when I check it in firebug console.

  But I get data as null when I check it in alert as shown below :

success :function(data){
                        alert(data);
var jsonObj = jQuery.parseJSON(data); 
alert( jsonObj);
}

Please help me if anyone knows the solution? Why I am not getting access token here?

mark mclaughlin

unread,
Jun 6, 2012, 1:05:18 AM6/6/12
to oauth...@googlegroups.com
Hi Gauri,

Did you ever find a solution here?

I've also tried sending the request via a .Net WebRequest but I've failed there too.

One thought is that your post data content type here is application/json...

Thanks,
Mark

Gauri B

unread,
Jun 6, 2012, 1:59:26 AM6/6/12
to oauth...@googlegroups.com
 Hi Mark,

    I am still stuck over there but I think we can't send XmlHttpRequest POST directly from our javascript code to another domain (You Tube).

    If you want to do authentication at client-side, check below links:

  
    Here is sample example given :

    Regards,
     Gauri

mark mclaughlin

unread,
Jun 6, 2012, 2:53:18 AM6/6/12
to oauth...@googlegroups.com
Thanks for your reply Gauri.

The CORS stuff looks like what I need.


Yeah, I guess I just expected this to be a little more straightforward, and I'm not sure why no one has written a step by step for this (maybe its in the CORS documentation, I just briefly looked at it).  With the links you sent me and this example I'll be able to get this done.

When I started with this OAuth2.0 stuff, I got the code from google in maybe 15 mins.   I've been working on the token for hours!  

I was trying to get the token on (client-side) in so many ways... I know how to make a post a request, I was putting the values in the query string url encoded and not, in the body of a request, I'm manually setting the content length, setting it to 0... changing the enctype, a callback url with http and with https...

This has been an unanticipated headache.  I'm working on this stuff as we speak and now I'm getting a 302 "Service Temporarily Moved" getting the auth code now!  Well, thanks Google, that's it, time to go to sleep.

I'm not going to criticize the CORS documentation, I haven't read through it yet - but when I'm done with this I'm going to write a step by step and post it on my site awesomejavascript.org

I'm currently frustrated.  405 Bad Request... 405 Bad Request... 405 Method Not Allowed...   Why Google, why?  
Reply all
Reply to author
Forward
0 new messages