2013-06-14 4 views
1

내 Google지도에 많은 마커를 표시하기 위해 WPF 응용 프로그램에서 google fustion table api를 구현하려고하지만 "GetAuthorization"기능을 인증하지 않을 때이 문제가 발생합니다..net FusiontablesService 인증 문제

public Fusion() 
    { 
     // Create the service. 
     objService = new FusiontablesService(new BaseClientService.Initializer() 
     { 
      Authenticator = CreateAuthenticator() 
     }); 

     //GetAuthorization(provider); 
    } 

    /// <summary> 
    /// The remote service on which all the requests are executed. 
    /// </summary> 
    public FusiontablesService objService { get; private set; } 
    NativeApplicationClient provider = null; 

    private IAuthenticator CreateAuthenticator() 
    { 
     provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) 
     { 
      ClientIdentifier = ClientCredentials.ClientID, 
      ClientSecret = ClientCredentials.ClientSecret 
     }; 
     return new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization); 
    } 

    private IAuthorizationState GetAuthorization(NativeApplicationClient client) 
    { 
     // You should use a more secure way of storing the key here as 
     // .NET applications can be disassembled using a reflection tool. 
     const string STORAGE = "google.samples.dotnet.fusion"; 
     const string KEY = "AIzaSyCtaH=6+"; 
     string scope = FusiontablesService.Scopes.Fusiontables.GetStringValue(); 

     // Check if there is a cached refresh token available. 
     IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); 
     if (state != null) 
     { 
      try 
      { 
       client.RefreshToken(state); 
       return state; // Yes - we are done. 
      } 
      catch (DotNetOpenAuth.Messaging.ProtocolException ex) 
      { 
       CommandLine.WriteError("Using existing refresh token failed: " + ex.Message); 
      } 
     } 

     // Retrieve the authorization from the user. 
     state = AuthorizationMgr.RequestNativeAuthorization(client, scope); 
     AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); 
     return state; 
    } 

이 문제를 도와주세요.

P.S이 코드는 TaskService 및 BookService를 사용할 때 잘 작동합니다.

답변

1

편집 : 나는 어떤 기능을 발견하지 않은 방법은 IAuthenticator 인터페이스

private IAuthenticator CreateAuthenticator() 
{ 
    provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) 
    { 
     ClientIdentifier = ClientCredentials.ClientID, 
     ClientSecret = ClientCredentials.ClientSecret 
    }; 
    var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization); 
    auth.LoadAccessToken() 
    return auth; 
} 
+0

에 노출되지 않도록 분실 "objService.Authenticator.LoadAccessToken을()". – Varun

+0

죄송합니다. OAuth2Authenticator 클래스의 일부만 잊어 버렸습니다. 코드를 업데이트했습니다. –