Monday, June 4, 2012

[YouTube-API] Re: OAuth2.0 Error : 405 method not allowed ?

Hello Gauri,

accounts.google.com doesn't support CORS, so you can't send a
XMLHttpRequest POST directly from your JavaScript code. (It's
annoying, I know, and I've previously spoken to the Auth team at
Google about adding support for this, but the situation applies
today.)

My recommendation is to use the Google APIs JavaScript library's
OAuth 2 functionality:

http://code.google.com/p/google-api-javascript-client/wiki/Authentication

There's an example of combining that library and the YouTube API at

http://gdata-samples.googlecode.com/svn/trunk/gdata/youtube_upload_cors.html

Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev


On Jun 2, 3:24 am, Gauri B <gauri...@gmail.com> wrote:
> Hi All,
>
>         I am facing one problem to get the access token for youtube API
> using oAuth2.0.  I got the 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({
> url:'https://accounts.google.com/o/oauth2/token',
> method: 'POST',
> host: 'accounts.google.com',
>                 contentType: 'application/x-www-form-urlencoded',
> data : {
> code : '4/MPH9vS5QCvJs9PB_b_tw5n3Avpvs.0vEfS-A70z4TgrKXntQAax0EzVBNbwI',
> client_id : '6656895612.apps.googleusercontent.com',
> client_secret : 'kiuSP80klPiYCB-xN8vYPi0R',
> redirect_uri : 'http://localhost:8080/user/admin/my-space',
> grant_type : 'authorization_code'},
>
> success :function(data){
> var jsonObj = jQuery.parseJSON(data);
> alert(jsonObj);
>  }
>
> });
>
>       In my above code, I am getting jsonObj as null.
>
>       I have gone through the forum, and read all the posts related to this
> error but I did not get any solution over there. Even I am sending the HTTP
> Post method instead of    Get method but still I get the same error.
>
>       Please let me know If there is anything wrong with the above code.
> Any help would be appreciated.
>
>      Thanks in advance.
>
>      Regards,
>       Gauri

--
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