【问题标题】:data is not retriving from outlook of office 365?没有从 Office 365 的 Outlook 中检索数据?
【发布时间】:2020-05-27 22:58:00
【问题描述】:
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
            .Create("dcb4a15***d745b428b2ac")
            .WithTenantId("8392***f0b-93b0-d4013318ea7d")
            .Build();
 var password = new SecureString();
            password.AppendChar('*');
            password.AppendChar('*');
            password.AppendChar('*');
UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

User me = await graphClient.Me.Request()
                .WithUsernamePassword("username.onmicrosoft.com", password)
                .GetAsync();
var queryOptions = new List<QueryOption>()
            {
                new QueryOption("startDateTime", "2020-02-18T16:00:00.0000000"),
                new QueryOption("endDateTime", "2020-02-18T16:00:00.0000000")
            };

            var calendarView = await graphClient.Me.Calendar.CalendarView
                .Request(queryOptions)
                .GetAsync();

上面的代码是为了在 c#.net 中获取日历视图而编写的,但它不起作用。我没有使用图表从日历中获取任何数据,我使用的是 bot 框架 4,我添加了 microsoft.graph、microsoft.graph.auth 包、microsoft.identity.client

【问题讨论】:

  • 你最好不要在帖子中包含任何个人信息,我已经编辑了你的帖子。

标签: c# .net botframework microsoft-graph-calendar


【解决方案1】:

我在 Main 方法中测试了代码,所以我使用 Task.Result 而不是 Await。我可以按预期获得 calendarView。

UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);
            GraphServiceClient graphClient = new GraphServiceClient(authProvider);
            User me = graphClient.Me.Request()
                .WithUsernamePassword("username.onmicrosoft.com", s)
                .GetAsync().Result;
            var queryOptions = new List<QueryOption>()
            {
                new QueryOption("startDateTime", "2020-02-12T16:00:00.0000000"),
                new QueryOption("endDateTime", "2020-02-18T16:00:00.0000000")
            };

            var calendarView = graphClient.Me.Calendar.CalendarView
                .Request(queryOptions)
                .GetAsync().Result;

我得到一个结果,因为我在“2020-02-12”和“2020-02-18”之间只有一个事件。我注意到您使用的时间与 startDateTime 和 endDateTime 相同。您需要检查 startDateTime 和 endDateTime 之间是否有日历事件。

【讨论】:

  • 我应该在 Program.cs 的 main 方法中使用这段代码
  • @Priya 我刚刚测试了Main方法中的代码,你应该把它放在你需要的地方。
  • @Priya Inside OnMessageActivityAsync
  • 我使用上面的代码,但仍然在 Microsoft.Graph.User 的机器人异常中显示错误“发生一个或多个错误。(代码:generalException 消息:发送请求时发生错误。)”我 = graphClient.Me.Request() .WithUsernamePassword("Tejaswini@indica.onmicrosoft.com", 密码) .GetAsync().Result; ,@Tony Ju,我使用了 app urn:ietf:wg:oauth:2.0:oob 的重定向 uri
  • 我收到此错误应用程序“13febApp2nd”要求范围“日历”。资源“00000003-0000-0000-c000-000000000000”上不存在的“读取”。联系应用供应商@Tony Ju
【解决方案2】:

以下代码有我的凭据时出现上述错误

UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);
            GraphServiceClient graphClient = new GraphServiceClient(authProvider);
            User me = graphClient.Me.Request()
                .WithUsernamePassword("username.onmicrosoft.com", s)
                .GetAsync().Result;
            var queryOptions = new List<QueryOption>()
            {
                new QueryOption("startDateTime", "2020-02-12T16:00:00.0000000"),
                new QueryOption("endDateTime", "2020-02-18T16:00:00.0000000")
            };

            var calendarView = graphClient.Me.Calendar.CalendarView
                .Request(queryOptions)
                .GetAsync().Result; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    • 2015-05-13
    相关资源
    最近更新 更多