我正在尝试使用刷新令牌进行离线访问。通过 httprequest,我必须使用保存的 refreshToken 获取新的 accessToken。
但我不断收到错误请求 400,没有进一步解释出了什么问题。有人可以告诉我此代码有什么问题或发布有效的代码吗?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
authenticator.ApplyAuthenticationToRequest(request);
request.Method = "POST";
String para = "code='"+refreshtoken+"'&client_id='" + ClientCredentials.CLIENT_ID + "'&client_secret='" + ClientCredentials.CLIENT_SECRET + "'&grant_type='refresh_token'";
System.IO.Stream requestStream = request.GetRequestStream();
System.IO.StreamWriter streamwriter = new System.IO.StreamWriter(requestStream);
streamwriter.Write(para);
streamwriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
String result = reader.ReadToEnd();