Wednesday, May 2, 2012

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

Hello Jeff,

I tried sending the post request but no luck. I was running into the same 405 error. Can you please look at the below code and see if you find anything wrong?

 WebRequest request = WebRequest.Create("https://accounts.google.com/o/oauth2/token");
          
            // Set the Method property of the request to POST.
            request.Method = "POST";

            // Create POST data and convert it to a byte array.
            string postData = "code=4/uHGXz1QBaJNaNKNR0zOfpWzip3bN";
            postData += ("&client_id= clientid ");
            postData += ("&client_secret=ClientSecret");
            postData += ("&redirect_uri=http://localhost:51799/youtube/YouTube/oauth2callback");
            postData += ("&grant_type=authorization_code");

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();
            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            // Get the response.
            WebResponse response = request.GetResponse();

Thanks,
Sagar

On Monday, 30 April 2012 15:57:13 UTC-5, Jeffrey Posnick wrote:
Hello Sagar,

 I assume you're talking about the server-side web application flow,
described at

  https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Server_Side_Web_Applications_Flow

 In step 4 in that flow, you need to send an HTTP POST request to that
endpoint to get back the tokens. I'm assuming you're sending something
else (like an HTTP GET), which would result in that 405 error.

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


On Apr 30, 3:31 pm, Sagar <sagarra...@gmail.com> wrote:
> Hello ,
>
> I had issues getting the access token for youtube API using oAuth2.0.  I
> got the the "code" parameter from the step 1:
>
> https://accounts.google.com/o/oauth2/auth?client_id=clientID&redirect...
>
> The resposnse for the above request was like :https://localhost:51799/oauth2callback?code=4/Oj16pMMdXfO410Ji5qP0nTc...
>
> And I tried to exchange the "code" parameter for access token but it's
> throwing an error 405, Method not allowed.
>
> Here is my http request :
>
> https://accounts.google.com/o/oauth2/token?code=4/Oj16pMMdXfO410Ji5qP...
> clientID &client_secret=clientsecret
> &redirect_uri= redirectlink &grant_type=authorization_code
>
> Even the simple http request for access token without any parameters
> "https://accounts.google.com/o/oauth2" throwing the same error.  Please let
> me know If there is anything wrong with the above request.  Any help would
> be appreciated.
>
> Thanks,
> Sagar

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/GYreqURi5pYJ.
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