【问题标题】:Access denied or Not Found errors from Graph API while Access other users calendar in Office 365在 Office 365 中访问其他用户日历时,来自 Graph API 的访问被拒绝或未找到错误
【发布时间】:2017-12-08 14:32:19
【问题描述】:

我想通过我在 Microsoft Office 365 上的管理员帐户访问我组织的其他用户日历。在 Office 365 上,我可以搜索和访问这些日历。 我想使用 Microsoft Graph API 访问这些(其他用户的)日历。 以下是使用 Graph API 访问 Office 365 日历的官方文档。 1.Calendars from Users 2.Directly Access Calenders

这是我的 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 /users/{id | userPrincipalName}/calendars 查询显示 404 Not Found 错误。

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

any of these methods.

【问题讨论】:

    标签: ruby-on-rails office365 microsoft-graph-api office365api outlook-calendar


    【解决方案1】:

    似乎只有在用户上下文之外运行的应用程序(如服务/守护程序应用程序)才能访问组织中的每个日历。 Getting access tokens for apps that run without the presence of a signed-in user is a bit different 您需要通过管理员同意流程才能让您的应用访问每个人的日历。我刚刚对此进行了测试,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 授予管理员对您的应用程序的许可

    获得访问令牌后,访问其他用户日历的其余调用正是您在问题中发布的内容:

    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 中查看我们的日历示例。

    【讨论】:

    • 我在用日历请求任何内容时不断收到 404。但我可以访问用户、组等任何建议?
    猜你喜欢
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多