交换刷新令牌时的异常

时间:2013-10-23 11:06:27

标签: asp.net oauth oauth-2.0 google-calendar-api

我开发了一个Google日历集成应用程序。当我使用日历服务时,我被困在一个地方。请检查以下代码。

private static IAuthorizationState GetAuthorization(NativeApplicationClient arg, String Refreshtoken)
{                    
    IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
    state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
    state.RefreshToken = Refreshtoken;
    try
    {
        if (arg.RefreshToken(state))     // This is calling out to the OAuth servers with the refresh token getting back a session token, returns true if successful.
        {
            if (state.RefreshToken != Refreshtoken) // if the refresh token has changed, save it.
            {
              //save token
            }
            return state; // Retain the authorization state, this is what will authenticate your calls.
        }
    }
    catch (Exception ex)
    {

    }
    return state;
}

我得到的例外是

Exception:
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request,         
DirectWebRequestOptions options) at 
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request) at 
DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest) at 
DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request) at     
DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage) at 
DotNetOpenAuth.Messaging.Channel.Request[TResponse](IDirectedProtocolMessage requestMessage) at 
DotNetOpenAuth.OAuth2.ClientBase.RefreshToken(IAuthorizationState authorization, Nullable`1 
skipIfUsefulLifeExceeds) at GoogleCalendarProvider_V3.GetAuthorization(NativeApplicationClient 
arg, String Refreshtoken)

Exception Message:
Error occurred while sending a direct message or getting the response. 

0 个答案:

没有答案