首页 > 解决方案 > Microsoft Graph 用于在 C# 中读取我自己的日历?

问题描述

我不是所有 Azure 方面的专家,但我想以编程方式阅读我自己的日历。我找到了一些代码来访问 Microsoft Graph 并阅读我的日历,但似乎我必须先创建一个应用注册,如果我只需要阅读我的OWN日历,是否可以跳过应用注册?这是我的出发点:

var scopes = new[] { "User.Read" };
var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

var userName = "myaccount@company.com";
var password = "pwdhere";

var userNamePasswordCredential = new UsernamePasswordCredential(
    userName, password, tenantId, clientId, options);

var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);   

var events = await graphClient.Me.Calendar.Events
    .Request()
    .Filter("startsWith(subject,'All')")
    .GetAsync();

标签: c#azuremicrosoft-graph-api

解决方案


您需要注册应用程序,否则您甚至无法登录。如果它是您无法控制的 Azure AD,例如您的雇主,您需要让管理员为您创建它。


推荐阅读