2012-03-20 14 views
4

ユーザーのGoogleカレンダーにアクセスするためのネイティブアプリを作成しようとしています。私は、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"); 
    } 
} 

を発射するようでないことの例を使用しようとしています。私は、コンソールライブラリが公開されることはありません。

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;を使用してください。 DLLはhttp://code.google.com/p/google-api-dotnet-client/wiki/APIs#Calendar_API – bossylobster

+0

でダウンロードできます – 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デベロッパー向けの良いドキュメントを提供していません