Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint 当我尝试请求组时,MS Graph API返回500_Sharepoint_Microsoft Graph Api - Fatal编程技术网

Sharepoint 当我尝试请求组时,MS Graph API返回500

Sharepoint 当我尝试请求组时,MS Graph API返回500,sharepoint,microsoft-graph-api,Sharepoint,Microsoft Graph Api,因此,我正在开发一个sharepoint Web部件,需要在其中检查用户是否在广告组中。下面是我需要向您介绍的MS Graph查询的奇怪部分: https://graph.microsoft.com/v1.0/me/transitiveMemberOf/microsoft.graph.group?$count=true 这正是我的WP发出的查询,但它返回一条500错误消息。现在我认为我缺少权限,但浏览器说我不需要任何权限 以下是我的GraphService,它处理MS Graph: impor

因此,我正在开发一个sharepoint Web部件,需要在其中检查用户是否在广告组中。下面是我需要向您介绍的MS Graph查询的奇怪部分:

https://graph.microsoft.com/v1.0/me/transitiveMemberOf/microsoft.graph.group?$count=true
这正是我的WP发出的查询,但它返回一条500错误消息。现在我认为我缺少权限,但浏览器说我不需要任何权限

以下是我的GraphService,它处理MS Graph:

import { MSGraphClient } from '@microsoft/sp-http';
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
import { WebPartContext } from "@microsoft/sp-webpart-base";

/**
 * The class that handles the MS Graph API calls
 */
export default class GraphService {
    /**
     * The MS Graph client with does the calls
     */
    private _client:MSGraphClient;

    /**
     * Sets the client for the Graph API, needs to be called before the class can be used
     * @param context The context of the WP
     */
    public async setClient(context:WebPartContext) {
        this._client = await context.msGraphClientFactory.getClient();
    }
    /**
     * Checks to see if a user belongs in a user group or not
     * @param groupName The group name with we want to check
     */
    public async checkCurrentUserGroup(groupName:string) {
        const rawData = await this._client.api('/me/transitiveMemberOf/microsoft.graph.group').count(true).get();
        const arr = rawData.value.filter(i => i.displayName == groupName);
        return !!arr.length;
    }


    /**
     * Returns the users from AD who have a manager and whom companyName is a specific company name
     * @param companyName The company name to whom the users need to belong to
     */
    public async getUsers(companyName:string):Promise<any[]> {
        const rawData = await this._client.api('/users').filter('accountEnabled eq true').expand('manager').select('displayName,companyName,mail,department,jobTitle').get();

        //need to do manual filtering, becuase you can't user filter on the "companyName" field and you can't search and expand at the same time without returing everything
        const filteredData = rawData.value.filter(i => i.companyName == companyName && i.manager);

        //remaps the data to IUserModel
        const ret:any[] = filteredData.map(i => <any>{
            name: i.displayName,
            id: 0,
            email: i.mail,
            manager: i.manager.displayName,
            managerEmail: i.manager.mail,
            managerId: 0,
            hasDiscussionForm: false,
            department: i.department,
            position: i.jobTitle
        });

        return ret;
        
    } 
}
然后问题是checkCurrentUserGroup方法返回500

我已授予wp以下权限:

小组阅读 Directory.Read.All 用户阅读 getUsers方法按预期工作


在MS Graph Explorer中,查询工作正常。我遗漏了什么?

根据文档,请求标头必须具有一致性级别和最终标头,请确保传递请求标头,请参阅此以了解更多信息

let res = await client.api('/users/{id}/transitiveMemberOf/microsoft.graph.group')
    .header('ConsistencyLevel','eventual')
    .search('displayName:tier')
    .select('displayName,id')
    .orderby('displayName ')
    .get();

根据文档,请求标头必须具有一致性级别和最终标头,请确保通过请求标头,并请参阅此以了解更多信息

let res = await client.api('/users/{id}/transitiveMemberOf/microsoft.graph.group')
    .header('ConsistencyLevel','eventual')
    .search('displayName:tier')
    .select('displayName,id')
    .orderby('displayName ')
    .get();

请通过传递头详细信息client.api'/users/{id}/transitiveMemberOf/microsoft.graph.group'.header'consistentylevel','final'让我们知道是否helps@SruthiJ-MSFTIdentity不,我没有,这实际上起了作用,ty,你能给我一个答案让我接受吗,也许能解释一下发生了什么事,如果没有太多问题,请尝试通过传递头详细信息client.api'/users/{id}/transitiveMemberOf/microsoft.graph.group'.header'consistentylevel','final'让我们知道它是否正确helps@SruthiJ-MSFTIdentity不,我没有,这确实有效,你能给我一个答案,这样我就可以接受它,也许可以解释一下发生了什么,如果不是太多的要求