【问题标题】:Google Calendar .Net API V3 domain wide delegationGoogle Calendar .Net API V3 域范围委托
【发布时间】:2014-06-12 17:02:52
【问题描述】:

我正在使用,

asp.net 4.0、Google 日历 API V3 和带有 Windows 2003 R2 网络服务器和 IIS 6.0 的环境,我们拥有自己的许可 Google 域

我的应用需要访问很多人的 Google 日历并添加/删除/更新事件,我们之前使用 V2 并使用消费者密钥和消费者密钥。目前我的代码已迁移到 V3 版本并且它可以工作,因为我正在使用使用 API 密钥和加密密钥文件的服务帐户类型。但我的客户不是很热衷,他们正在研究类似 OAuth 2.0 和 V2 版本的身份验证。

所以我的问题是,除了使用 V3 的服务帐户之外,为一堆用户执行所有操作的最佳方法是什么,这些用户应该像使用 V2 一样进行一次身份验证?

谢谢, 虚拟机

【问题讨论】:

    标签: c# oauth-2.0 google-calendar-api


    【解决方案1】:

    您可以使用日历 API V3 和 Web 授权。在这种情况下,网页将被重定向到用户同意屏幕,然后最终用户应授权请求。

    using System;
    using System.Threading;
    using System.Threading.Tasks;
    
    using Google;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Calendar.v3;
    using Google.Apis.Calendar.v3.Data;
    using Google.Apis.Services;
    
    namespace Calendar.Sample
    {
        class Program
        {
            static void Main(string[] args)
            {
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
                    {
                        ClientId = "CLIENT_ID_HERE",
                        ClientSecret = "CLIENT_SECRET_HERE",
                    },
                    new[] { CalendarService.Scope.Calendar },
                    "user",
                    CancellationToken.None).Result;
    
                // Create the service.
                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Calendar API Sample",
                });
    
                ...
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2022-07-31
      • 1970-01-01
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      相关资源
      最近更新 更多