Hello Sagar,
The only thing that immediately jumps out is that you appear to have
extra space characters around your clientid variable, but maybe that's
just an artifact of you having edited your code before posting. You
could try using Fiddler to intercept your code's HTTPS traffic and
ensure that what you're sending matches the example in the docs:
http://www.fiddler2.com/fiddler2/
As an alternative, have you considered using the OAuth 2 library
provided as part of the Google APIs .NET Client Library?
http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Using_OAuth2.0
While the rest of the client library doesn't natively support YouTube,
you should be able to use just the OAuth 2 portion of that library to
handle auth for you and get back a token you could use with the
existing GData .NET Client Library.
Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev
On May 2, 6:28 pm, Sagar <sagarra...@gmail.com> wrote:
> 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_o...
>
> > 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 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