使用jQueryAjax调用MicrosoftGraphAPI和officeLocation返回null

使用jQueryAjax调用MicrosoftGraphAPI和officeLocation返回null,jquery,microsoft-graph-api,Jquery,Microsoft Graph Api,我在使用Microsoft Graph API时遇到问题。我正在使用jQuery.ajax()调用/users,并使用一些属性进行筛选,包括officeLocation。大多数时候,当我在SharePoint Online中运行它时,它会返回officeLocation的null 范围:openidUser.ReadBasic.All人。Read日历。ReadWrite 这是我的密码: function getLocationListByType(type, callback) { ge

我在使用Microsoft Graph API时遇到问题。我正在使用
jQuery.ajax()
调用
/users
,并使用一些属性进行筛选,包括
officeLocation
。大多数时候,当我在SharePoint Online中运行它时,它会返回
officeLocation
null

范围:
openid
User.ReadBasic.All
人。Read
日历。ReadWrite

这是我的密码:

function getLocationListByType(type, callback) {
    getAccessToken(function (accessToken) {
        if (accessToken) {
            type = handleEscapeParam(type);

            if (type == 'Room') {
                type = 'room';
            } else {
                type = 'equipment';
            }

            $.ajax({
                type: "GET",
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('Authorization', 'bearer ' +
                        sessionStorage.accessToken);
                },
                url: "https://graph.microsoft.com/v1.0/users?$filter=surname eq '" +
                    type + "'&$select=id,displayName,mail,officeLocation&$top=999",
                success: function (res) {
                    callback(restructuringData(res.value));
                },
                error: function (error) {
                    callback(error);
                }
            });
        } else {
            var error = {
                responseText: 'Could not retrieve access token'
            };
            callback(null, error);
        }
    });
}

您正在请求
User.ReadBasic.All
作用域,该作用域仅提供对一组非常有限的属性的访问:

  • id
  • displayName
  • givenName
  • 邮件
  • 姓氏
  • userPrincipalName
  • photo

为了检索
officeLocation
,您需要请求
User.Read.All
范围。但是,这确实需要更高的权限,因此您还需要从租户中的全局管理员处接收

你在代币上要求什么范围?感谢上帝你在这里,马克。我的全部范围:“openid User.ReadBasic.All People.Read Calendars.ReadWrite”第一个问题写得很好。欢迎来到StackOverflow(+1)。嗨@Marclafler,非常感谢您的时间和回答。实际上,我尝试了
/users
的所有范围,但是
officeLoaction
仍然是
null
。然而,当我回到办公室时,我会再试一次。再次感谢您。亲爱的@Marclafler,您的回答很有帮助,我确实通过
User.Read.All
scope获得了
officeLocation
的值。非常感谢。