Sag*_*gar 11 c# asp.net google-api oauth-2.0
我正在使用C#(ASP.NET).我想使用Google oauth访问我的应用中的用户个人资料详情.我成功获得了授权码,但在获取访问令牌时遇到了问题.我更喜欢Google教程.在教程中,我读到我必须发送请求并从谷歌获得响应.为此我使用System.Net.HttpWebRequest/HttpWebResponse(我是以正确的方式).我用这个代码....
byte[] buffer = Encoding.ASCII.GetBytes("?code=" + code + "&client_id=xxx&client_secret=xxx&redirect_uri=xxxx&grant_type=authorization_code");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://accounts.google.com");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
Stream strm = req.GetRequestStream();
strm.Write(buffer, 0, buffer.Length);
strm.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Response.Write(((HttpWebResponse)resp).StatusDescription);
Run Code Online (Sandbox Code Playgroud)
但是,我收到了错误:
远程服务器返回错误:(405)方法不允许.
更新:此变量code是授权代码.
我认为你正在向错误的端点发送POST请求,正确的是 https://accounts.google.com/o/oauth2/token
| 归档时间: |
|
| 查看次数: |
29332 次 |
| 最近记录: |