Migración de la versión V3 (1.5.0.56-beta) del calendario de Google a la última Dlls, es decir, la versión 3 (1.8.1.820)

Estoy usando Google calendar versión 3 (1.5.0.56-beta) beta para mi aplicación asp.net, ahora quiero actualizar estos archivos DLL a la versión 3 (1.8.1.820). He descargado las nuevas DLL pero no muestra que NativeApplicationClient, GoogleAuthenticationServer no están en estas DLL. Verifique el siguiente código que estoy usando para la versión beta V3

private CalendarService CreateService(string token)
{
    KeyValuePair<string, string> credentials = Common.Get3LOCredentials();
    var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
    provider.ClientIdentifier = credentials.Key;
    provider.ClientSecret = credentials.Value;
    var auth = new Google.Apis.Authentication.OAuth2.OAuth2Authenticator<NativeApplicationClient>(provider, (p) => GetAuthorization(provider, token, credentials.Key, credentials.Value));
    CalendarService service = new CalendarService(new BaseClientService.Initializer()
    {
        Authenticator = auth,
        ApiKey = ConfigurationManager.AppSettings["APIkey"].ToString(),
        GZipEnabled = false
    });
    provider = null;
    return service;
}
 private IAuthorizationState GetAuthorization(NativeApplicationClient arg, String Refreshtoken, string clientid, string clientsecret)
{
    int retrycount = 0;
    IAuthorizationState state = null;
    string accesstoken = string.Empty;

    while (retrycount < 7)
    {
        accesstoken = string.Empty;
        try
        {
            state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);// NativeApplicationClient.OutOfBandCallbackUrl);                
            ProfileSettingsBL bl = BLFactory.CurrentInstance.ProfileSettingsBLObj;
            ProfileSettingsDS.SOUserCalendarAccountRow row = bl.RetrieveSOUserCalendarAccountByToken(Refreshtoken);
            if (row != null)
            {
                string[] splitter = new string[1];
                splitter[0] = Constants.EQUAL_REPLACE_STRING;
                string[] arr = row.Token.Split(splitter, StringSplitOptions.None);
                if (arr.Length == 1)
                {
                    accesstoken = ExchangeCodeWithAccessAndRefreshToken(Refreshtoken, clientid, clientsecret, retrycount);
                    if (!string.IsNullOrEmpty(accesstoken))
                    {
                        string[] arr1 = accesstoken.Split(splitter, StringSplitOptions.None);
                        if (arr1.Length > 1)
                        {
                            bl.updateAccessToken(Refreshtoken, arr1[0], arr1[1]);
                            accesstoken = arr1[0];
                        }
                    }
                }
                else
                {
                    if (arr.Length >= 1)
                        accesstoken = arr[1];
                }
            }
            else
            {
                string[] splitter = new string[1];
                splitter[0] = Constants.EQUAL_REPLACE_STRING;
                accesstoken = ExchangeCodeWithAccessAndRefreshToken(Refreshtoken, clientid, clientsecret, retrycount);
                if (!string.IsNullOrEmpty(accesstoken))
                {
                    string[] arr1 = accesstoken.Split(splitter, StringSplitOptions.None);
                    if (arr1.Length >= 1)
                        accesstoken = arr1[0];
                }
            }
            if (!string.IsNullOrEmpty(accesstoken))
                state.AccessToken = accesstoken;
            state.RefreshToken = Refreshtoken;               
            return state;
        }
        catch (Exception ex)
        {

        }
    }
    return state;
}

¿Alguien puede ayudarme en este sentido? No puedo encontrar una buena documentación para los desarrolladores de .NET. Gracias de antemano.

preguntado el 28 de mayo de 14 a las 14:05

1 Respuestas

Ahora he convertido la aplicación anterior en una nueva, aquí solo necesita usar la clase UserCredential que se encuentra dentro de Google.Apis.Auth.OAuth2. Por favor revise el siguiente código para esto.

private CalendarService CreateService(string token)
{
    KeyValuePair<string, string> credentials = Common.Get3LOCredentials();
    String AccessToken = GetAuthorization(RefreshToken, credentials.Key, credentials.Value);
    var tokenCode = new TokenResponse() { RefreshToken = RefreshToken, AccessToken = AccessToken };
    var secreat = new ClientSecrets() { ClientId = credentials.Key, ClientSecret = credentials.Value };
    UserCredential credential = new UserCredential(new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
    {
        ClientSecrets = secreat
    }), "user", tokenCode);
    var service = new CalendarService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "Google Calendar API Sample",
    });
    return service;
}

Es realmente muy fácil que antes el código que tenía Google en las versiones Beta.

contestado el 29 de mayo de 14 a las 14:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.