我已成功通过 Google OAuth API 进行身份验证。第一次正确运行。对于第二次访问相同的内容,我收到以下错误:
“发送直接消息或获取响应时发生错误。”
堆栈跟踪:
[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +6038435
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) +410
[ProtocolException: Error occurred while sending a direct message or getting the response.]
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) +1618
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request) +73
DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest) +82
DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request) +357
DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage) +158
DotNetOpenAuth.OAuth2.ClientBase.UpdateAuthorizationWithResponse(IAuthorizationState authorizationState, EndUserAuthorizationSuccessAuthCodeResponse authorizationSuccess) +319
DotNetOpenAuth.OAuth2.WebServerClient.ProcessUserAuthorization(HttpRequestInfo request) +885
对于方法
private IAuthorizationState GetAuthorization(WebServerClient client)
{
String accesstoken = "";
IAuthorizationState state = AuthState;
if (state != null)
{
return state;
}
state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
if (state != null && (!string.IsNullOrEmpty(state.AccessToken)
|| !string.IsNullOrEmpty(state.RefreshToken)))
{
accesstoken = state.AccessToken;
HttpContext.Current.Session["AUTH_STATE"] = _state = state;
return null;
}
string scope = TasksService.Scopes.TasksReadonly.GetStringValue();
OutgoingWebResponse response = client.PrepareRequestUserAuthorization(new[] {
scope,
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
});
response.Send();
return null;
}
private IAuthorizationState AuthState
{
get
{
return _state ?? HttpContext.Current.Session["AUTH_STATE"] as IAuthorizationState;
}
}
在行中
state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
等待有价值的回复和评论