2012-03-30 9 views
1

Google 캘린더 API V3을 사용하여 캘린더를 업데이트하려고합니다. 내 캘린더의 이벤트를 C# 코드에서 가져 오려고합니다. Google 캘린더 API V3 용 .NET 라이브러리를 사용하고 있습니다.Google 캘린더 API V3

어떤 이유로 든 내 요청을 승인 할 수 없습니다. 사용 가능한 코드 샘플을 따르려고했으나 헛되지 않았습니다. 직접 메시지 또는

를 전송하는 동안

프로토콜 예외 오류가 발생했습니다 : if (arg.RefreshToken(state))이 실행될 때이 예외를받을

private void GetEvents() 
    { 
     var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description,MyClientId, MySecurityId); 
     var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization); 

     CalendarService myService = new CalendarService(auth); 
     try 
     { 
      Events result = myService.Events.List(MyCalendarId).Fetch(); 

      if (result.Items.Count > 0) 
      { 
      } 
     } 
     catch (Google.GoogleApiRequestException ex) 
     { 
      //throw ex; 
     } 
    } 

    private static IAuthorizationState GetAuthorization(NativeApplicationClient arg) 
    { 
     IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/calendar.readonly" }); 

     state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);   

     if (!string.IsNullOrEmpty(refreshToken)) // refreshToken you stored in step 4 
     { 
      try 
      { 
       state.RefreshToken = refreshToken; 
       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. 
        { 
         //PersistRefreshToken(authorization.RefreshToken); 
        } 
        return state; // Retain the authorization state, this is what will authenticate your calls. 
       } 
      } 
      catch (ProtocolException ex) { throw ex; } 
     } 
     return state; 
    } 

: 다음은 내 요청을 승인 사용하고 내 코드입니다

응답을 받고 있습니다.

Please HELP !!!

+0

여기에서이 게시물을 살펴보고 도움이되는지 확인해보십시오. http://stackoverflow.com/questions/8899000/c-sharp-google-calendar-v3-2-legged-authentication-fails – HK1

답변

0

웹 서버 또는 기본 응용 프로그램에서 이것을 사용하고 있습니까? 이 코드는 네이티브 응용 프로그램에만 해당하므로 문제가 될 수 있습니다.