简体   繁体   English

使用API​​ v3在Google日历中创建事件

[英]Creating Event in Google calendar using api v3

I have tryed this sample from google in c#.net but it is not working for me. 我已经在c#.net中尝试了来自Google的此示例,但是它不适用于我。 any one have any sample for google calendar api v3 任何人都有Google日历api v3的任何示例

it is showing me the error as AuthenticatorFactory does not existing in current content. 它向我显示错误,因为AuthenticatorFactory当前内容中不存在。

I use the dll give by the google 我用谷歌给的dll

using System;
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Util;
namespace Sample.Console
{
    class Program
    {
       static void Main(string[] args)
        {
            // Register the authenticator. The Client ID and secret have to be copied from the API Access
           // tab on the Google APIs Console.
        var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
        provider.ClientIdentifier = "YOUR_CLIENT_ID";
        provider.ClientSecret = "YOUR_CLIENT_SECRET";
        AuthenticatorFactory.GetInstance().RegisterAuthenticator(
                () => new OAuth2Authenticator(provider, GetAuthentication));

        // Create the service. This will automatically call the previously registered authenticator.
        var service = new CalendarService();
    }
    private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
    {
        // Get the auth URL:
        IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
        state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
        Uri authUri = arg.RequestUserAuthorization(state);

        // Request authorization from the user (by opening a browser window):
        Process.Start(authUri.ToString());
        Console.Write("  Authorization Code: ");
        string authCode = Console.ReadLine();
        Console.WriteLine();

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

Instead of using the Auth Factory use OAuth2 authenticator object, google did not document this change very well...just remove the code with AuthenticatorFactory.GetInstance().... and replace with this line of code. 谷歌没有使用Auth Factory使用OAuth2身份验证器对象,而是没有很好地记录此更改...仅使用AuthenticatorFactory.GetInstance()删除了代码,然后用此行代码替换。 Everything else should stay the same. 其他一切都应该保持不变。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM