惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
I
InfoQ
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
WordPress大学
WordPress大学
B
Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
博客园 - 聂微东
Jina AI
Jina AI

博客园 - 启明星工作室

高等数学在线入门教程(零基础适配) Latex安装Texlive Authenticate an EWS application by using OAuth codemirror 高等数学课件 线性代数课件 概率论与数理统计课件 使用 Microsoft Graph oFFICE365 sendmail C# C# String 字符串转换为base64 C#语言async, await 简单介绍与实例(入门级) 启明星工作室网站改版了 dotnetcms.cn 数学题库管理系统 Math 面向老师的单机版“数学系统math” 启明星Helpdesk系统,欢迎大家使用。 启明星人物评选投票系统,欢迎大家使用 微信安装包从0.5M暴涨到260M,为什么我们的程序越来越大? Kmath里MathJax和markdown整合 Windows下TeXLive 环境的安装与配置 MathPix
Microsoft.Exchange.WebServices.Data;
启明星工作室 · 2023-05-15 · via 博客园 - 启明星工作室

using Microsoft.Exchange.WebServices.Data;

using Microsoft.Identity.Client;

using System;

using System.Configuration;

namespace EwsOAuth

{

    class Program

    {

        static async System.Threading.Tasks.Task Main(string[] args)

        {

            // Using Microsoft.Identity.Client 4.22.0

            var cca = ConfidentialClientApplicationBuilder

                .Create(ConfigurationManager.AppSettings["appId"])

                .WithClientSecret(ConfigurationManager.AppSettings["clientSecret"])

                .WithTenantId(ConfigurationManager.AppSettings["tenantId"])

                // Use the next line of code only in a 21V environment

                .WithAuthority(AzureCloudInstance.AzureChina, ConfigurationManager.AppSettings["tenantId"])

                .Build();

            //the permission scope required for EWS access

            var ewsScopes = new string[] { "https://partner.outlook.cn/.default" };

            try

            {

                //make the token request

                var authResult = await cca.AcquireTokenForClient(ewsScopes).ExecuteAsync();

                // Configure the ExchangeService with the access token

                var ewsClient = new ExchangeService();

                ewsClient.Url = new Uri("https://partner.outlook.cn/EWS/Exchange.asmx");

                ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);

                ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "S02@ms10.online");

                //Include x-anchormailbox header

                ewsClient.HttpHeaders.Add("X-AnchorMailbox", "S02@ms10.online");

                // Make an EWS call

                DateTime endDate = DateTime.Now;

                DateTime startDate = endDate.AddDays(-30);

                CalendarFolder calendar = CalendarFolder.Bind(ewsClient, WellKnownFolderName.Calendar, new PropertySet());

                CalendarView cView = new CalendarView(startDate, endDate);

                cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

                FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

                Console.WriteLine("\nThe first " + " appointments on your calendar from " + startDate.Date.ToShortDateString() +

             " to " + endDate.Date.ToShortDateString() + " are: \n");

                foreach (Appointment a in appointments)

                {

                    Console.Write("Subject: " + a.Subject.ToString() + " ");

                    Console.Write("Start: " + a.Start.ToString() + " ");

                    Console.Write("End: " + a.End.ToString());

                    Console.WriteLine();

                }

            }

            catch (MsalException ex)

            {

                Console.WriteLine($"Error acquiring access token: {ex}");

            }

            catch (Exception ex)

            {

                Console.WriteLine($"Error: {ex}");

            }

            if (System.Diagnostics.Debugger.IsAttached)

            {

                Console.WriteLine("Hit any key to exit...");

                Console.ReadKey();

            }

        }

    }

}