我已成功通过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));
等待有价值的回复和评论
答案 0 :(得分:0)
请检查您是否只调用了client.ProcessUserAuthorization一次。从具有相同参数的第二次调用开始,可以继续“发送直接消息或获得响应”错误。