首页 > 解决方案 > 使用 Oauth2 从 Outlook 日历 API 获取代码

问题描述

我正在使用.net core 和 Angular 使用日历 API。我使用 Google Calendar API 完成了所有步骤。现在我想使用 Outlook 日历 API 来完成。所以首先我需要一个Angular中的函数,这样我就可以连接到我的帐户并获取一个代码(Oauth2),我将在后端使用它来获取我的令牌(因为我想在我的数据库中注册它们)。好吧,这是我使用 Google API 的功能

  handleAuthClick() {
    let self = this;
    gapi.auth2.getAuthInstance().grantOfflineAccess()
      .then(value => {
        const optionsParams = {
          params: new HttpParams()
            .set('code', value.code)
        };
        self.http.get("http://localhost:59933/api/UserCode", optionsParams)
          .subscribe(data => {
            console.log(data);
          })
      });
  }

我想我可能需要函数或库中的这个链接?任何人都可以帮助使用 Outlook 日历 API 的功能吗 谢谢

标签: angularasp.net-coreoutlook-calendar

解决方案


建议使用Microsoft Graph API来访问包括 Outlook 在内的 Microsoft 365 服务。

对于 Angular,您可以参考教程:Microsoft Graph 和 Angular 入门。它在 Angular 中提供 SDK 和代码示例。

GitHub 上还有几个 Angular 示例:https ://github.com/search?q=angular+sample+user:microsoftgraph&type=Repositories

此外,您的链接显示使用授权代码流获取 Microsoft Graph API 的访问令牌(范围是https://graph.microsoft.com/user.read),您可以在基于 javascript 的应用程序中使用隐式流。


推荐阅读