【发布时间】:2011-10-04 12:41:52
【问题描述】:
我正在尝试使用 GData 和 OAuth2.0 服务器端 (Check this link) 访问 Google 数据(联系人、编辑个人资料数据、日历...等),我完成了第一步并获得了第一个代码,当尝试发布获取 oauth2_token 的请求时,我总是收到错误 “远程服务器返回错误:(400)错误请求。” 这是我用来发布返回 OAuth2_token 的请求的代码:
string clientToken = Request.QueryString["code"];
string post =
string.Format(
@"code={0}&client_id={1}&client_secret={2}&redirect_uri=http://localhost/default.aspx&grant_type=authorization_code",
clientToken, Settings.ClientId, Settings.ClientSecret);
WebRequest httpRequest = WebRequest.Create("https://accounts.google.com/o/oauth2/token");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter streamWriter = new StreamWriter(httpRequest.GetRequestStream());
streamWriter.Write(post);
streamWriter.Flush();
streamWriter.Close();
var ss = (HttpWebResponse)httpRequest.GetResponse();
Stream stream = ss.GetResponseStream();
有什么帮助???到现在我花了 2 天时间试图解决它,但徒劳无功:(
【问题讨论】:
-
您是否向 Google 注册了重定向 URI?
-
你的意思是在 Google API 控制台code.google.com/apis/console ??是的,我做到了
标签: c# asp.net gdata-api oauth-2.0