2

我已成功通过 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));

等待有价值的回复和评论

4

1 回答 1

0

请检查您是否只调用了一次 client.ProcessUserAuthorization。从具有相同参数的第二次调用开始,它可能会继续“发送直接消息或获取响应”错误。

于 2013-08-13T09:39:32.913 回答