public ActionResult GetoAuthToken() { String url = "https://accounts.Google.com/o/oauth2/token"; // Create a request using a URL that can receive a post. httpWebRequest request = (httpWebRequest)WebRequest.Create(url); // Set the Method property of the request to POST. request.Method = "POST"; request.Host = "accounts.Google.com"; // Create POST data and convert it to a byte array. string postData = String.Format("code={0}&clIEnt_ID={1}&clIEnt_secret={2}&redirect_uri={3}&grant_type=authorization_code",Request.queryString["code"].ToString(),OAuthConfig.clIEnt_ID,OAuthConfig.clIEnt_secret,OAuthConfig.token_redirect_uri); ASCIIEnCoding enCoding = new ASCIIEnCoding(); byte[] byteArray = enCoding.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,byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // SOME CODE TO PROCESS THE RESPONSE Response.Redirect("/Home"); return VIEw(); }
OAuthConfig只是一个包含客户端ID,客户端密钥等的类.
我一直得到’远程服务器返回错误:(400)错误请求.在request.GetResponse()行.我哪里错了?
解决方法 谷歌确实提供了一个更高级别的库来处理它的服务,它处理网址的格式,我发现它可以更容易地使用它们的API.见 http://code.google.com/p/google-api-dotnet-client/ 总结以上是内存溢出为你收集整理的c# – google api oauth访问令牌检索 – 400个错误请求全部内容,希望文章能够帮你解决c# – google api oauth访问令牌检索 – 400个错误请求所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)