繁体   English   中英

访问Office 365中的其他用户日历时从Graph API访问被拒绝或找不到错误

[英]Access denied or Not Found errors from Graph API while Access other users calendar in Office 365

我想从Microsoft Office 365上的管理员帐户访问组织的其他用户日历。在Office 365上,我可以搜索和访问这些日历。 我想使用Microsoft Graph API访问这些(其他用户)日历。 这是使用Graph API访问Office 365日历的官方文档。 1. 用户日历 2. 直接访问日历

这是我的Auth Helper类,我在其中定义权限范围

module AuthHelper

  CLIENT_ID = '91e6****-****-40f7-9b46-******d1149c'
  CLIENT_SECRET = 'pftjo*******55;hwSN2-(%'

  SCOPES = [ 'openid',
             'profile',
             'User.Read',
             'Mail.Read',
             'Calendars.Read',
             'Calendars.Read.Shared' ]

  def get_login_url
    client = OAuth2::Client.new(CLIENT_ID,
                                CLIENT_SECRET,
                                :site => 'https://login.microsoftonline.com',
                                :authorize_url => '/common/oauth2/v2.0/authorize',
                                :token_url => '/common/oauth2/v2.0/token')

    login_url = client.auth_code.authorize_url(:redirect_uri => authorize_url, :scope => SCOPES.join(' '))
  end

  def get_token_from_code(auth_code)
    client = OAuth2::Client.new(CLIENT_ID,
                                CLIENT_SECRET,
                                :site => 'https://login.microsoftonline.com',
                                :authorize_url => '/common/oauth2/v2.0/authorize',
                                :token_url => '/common/oauth2/v2.0/token')

    token = client.auth_code.get_token(auth_code,
                                   :redirect_uri => authorize_url,
                                   :scope => SCOPES.join(' '))
  end

尝试邮递员:

https://graph.microsoft.com/v1.0/users查询以及标题,向我显示所有用户,但

GET /用户/ {id | userPrincipalName} / calendars查询,显示“ 404未找到”错误。

简而言之,我可以从office365应用程序的搜索栏中访问其他用户的日历,但不能使用

这些方法中的任何一种

看起来只有在用户上下文之外运行的应用程序(例如服务/守护程序应用程序)才能访问组织中的每个日历。 获取在没有登录用户的情况下运行的应用程序的访问令牌有些不同 ,您需要通过管理员同意流程才能使您的应用程序可以访问每个人的日历。 我刚刚对此进行了测试, Calendars.Read是您唯一需要的范围。

在此处输入图片说明

这些步骤是:

  1. 注册您的应用
  2. 添加Calendars.Read为应用程序权限
  3. 通过访问https://login.microsoftonline.com/{REPLACE WITH TENANT}/adminconsent?nonce=graph&prompt=select_account&client_id={REPLACE_WITH_APP_ID}&response_type=token&redirect_uri=https://localhost:3001&state=foobar这样的URL,授予管理员对您的应用程序的同意https://login.microsoftonline.com/{REPLACE WITH TENANT}/adminconsent?nonce=graph&prompt=select_account&client_id={REPLACE_WITH_APP_ID}&response_type=token&redirect_uri=https://localhost:3001&state=foobar

获得访问令牌后,剩下的访问另一个用户日历的调用就是您在问题中发布的内容:

GET https://graph.microsoft.com/v1.0/users/[user-id]/calendars

获得日历ID后,您可以在以下位置查看其日历事件:

GET https://graph.microsoft.com/v1.0/users/[user-id]/calendars/[calendar-id]/events

我鼓励您在Graph Explorer中查看我们的日历示例。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM