2012-03-20 5 views
4

사용자 Google 캘린더에 액세스하기위한 기본 앱을 작성하려고합니다. 나는 구글이 인증을 얻기 위해 제공하고있는 예제를 사용하려고하지만 결코 인증 기능 여기Google 인증 프로세스

private void Window_Initialized(object sender, EventArgs e) 
{ 
    var provider = new NativeApplicationClient(
      GoogleAuthenticationServer.Description); 
    provider.ClientIdentifier = "<My Client Id here>"; 
    provider.ClientSecret = "<My Client Secret here"; 

    var auth = new OAuth2Authenticator<NativeApplicationClient>(
     provider, (p) => GetAuthorization(provider)); 

    CalendarService service = new CalendarService(); 
    CalendarsResource.GetRequest cr = service.Calendars.Get("{primary}"); 

    if (cr.CalendarId != null) 
    { 
     Console.WriteLine("Fetching calendar"); 
     //Google.Apis.Calendar.v3.Data.Calendar c = 
      service.Calendars.Get("{primary}").Fetch(); 
    } 
    else 
    { 
     Console.WriteLine("Service not found"); 
    } 
} 

에게 해고 것 같다 것은 내가 인증에 사용하고있는 코드입니다. 나는 콘솔 writeline이 공개되는 것을 결코 보지 못한다.

private static IAuthorizationState GetAuthorization(NativeApplicationClient arg) 
{ 
    Console.WriteLine("Authorization Requested"); 

    IAuthorizationState state = new AuthorizationState(
     new[] { CalendarService.Scopes.Calendar.GetStringValue() }); 
    state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); 
    Uri authUri = arg.RequestUserAuthorization(state); 

    Process.Start(authUri.ToString()); 
    // Request authorization from the user and get the code 
    string authCode = Console.ReadLine(); 

    // Retrieve the access token by using the authorization code: 
    return arg.ProcessUserAuthorization(authCode, state); 
} 

더 나은 자습서가 있습니까? 아니면 내가 잘못하고 있습니까?

+0

동일한 문제가 발생했기 때문에이 문제를 해결할 수 있었습니까? – Varun

답변

0

새로운 docs을 확인하십시오. 주석이 말한대로 당신이 var service = new CalendarService()를 호출 할 때,

AuthenticatorFactory.GetInstance().RegisterAuthenticator(
    () => new OAuth2Authenticator(provider, GetAuthentication)); 

var auth = new OAuth2Authenticator<NativeApplicationClient>(
    provider, (p) => GetAuthorization(provider)); 

를 교체해야합니다, 이전에 등록 된 인증이 자동으로 호출됩니다.

+0

이것을 사용하려면 어떤 참조를 추가해야합니까? Visual Studio에서이 코드를 추가하면 공장을 찾을 수없고 해결 조치도 없다고 말합니다. – joshwl2003

+0

샘플에서와 같이,'using System; System.Diagnostics를 사용하여; DotNetOpenAuth.OAuth2를 사용; Google.Apis.Authentication; Google.Apis.Authentication.OAuth2; Google.Apis.Autisication.OAuth2.DotNetOpenAuth를 사용하여; Google.Apis.Calendar.v3; Google.Apis.Calendar.v3.Data; Google.Apis.Util;을 사용합니다. http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Calendar_API – bossylobster

+0

에서 DLL을 다운로드하면 같은 문제가 계속 발생하지 않습니다. – Varun

2

예제 코드가 손상되었습니다. 서비스에서 사용자 인증자를 사용하려면 연결해야합니다. 이 예에서는 서비스와 인증 자간에 연관이 없습니다. 더 좋은 문서/작업 코드에 대한 https://code.google.com/p/google-api-dotnet-client/에서

var service = new CalendarService(new BaseClientService.Initializer() 
{ 
    Authenticator = auth 
}; 

봐 :이 같은 서비스를 만듭니다.

0

위의 방법은 Google 캘린더 DLL의 이전 버전과 관련이 있다고 생각합니다. 어느 누구도 새로운 버전의 Google 캘린더, 즉 V 1.8.1.82에 대한 문서를 알고 있습니까? Google은 .NET 개발자를위한 좋은 설명서를 결코 제공하지 않습니다.