Sharepoint C#的图形API:BadGateway尝试在Office 365上创建团队时的结果

Sharepoint C#的图形API:BadGateway尝试在Office 365上创建团队时的结果,sharepoint,azure-active-directory,microsoft-graph-api,microsoft-graph-teams,Sharepoint,Azure Active Directory,Microsoft Graph Api,Microsoft Graph Teams,几天以来,我一直在研究一个解决方案,该解决方案通过SharePoint中的网站集创建一个团队和小组。我在尝试将新团队创建到组中时收到了一些与BadGateway相关的错误消息 这是引发异常的代码: var team = new Team { MemberSettings = new TeamMemberSettings { AllowC

几天以来,我一直在研究一个解决方案,该解决方案通过SharePoint中的网站集创建一个团队和小组。我在尝试将新团队创建到组中时收到了一些与BadGateway相关的错误消息

这是引发异常的代码:

 var team = new Team
                {
                    MemberSettings = new TeamMemberSettings
                    {
                        AllowCreateUpdateChannels = true
                    },
                    MessagingSettings = new TeamMessagingSettings
                    {
                        AllowUserEditMessages = true,
                        AllowUserDeleteMessages = true
                    },
                    FunSettings = new TeamFunSettings
                    {
                        AllowGiphy = true,
                        GiphyContentRating = GiphyRatingType.Strict
                    }
                };

                await graphClient.Groups[groupid].Team
                    .Request()
                    .PutAsync(team);
引发的异常是:

Code: BadGateway
Message: Failed to execute backend request.
Inner error:
    AdditionalData:
    request-id: a3ecc097-6969-4263-84dd-e6c3fd60bd03
    date: 2020-04-18T13:02:43
ClientRequestId: a3ecc097-6969-4263-84dd-e6c3fd60bd03
还有一些评论:

  • 执行的用户是网站集管理员(当此对象初始化时)
  • 客户端机密Id和Azure中的应用注册具有以下权限:

  • 我用于声明团队对象的特定版本是Assembly Microsoft.Graph,使用Nuget的版本=3.3.0.0。我在使用3.2.0.0时也遇到了同样的问题

  • 我知道可以直接使用RESTAPI执行相同的方法,但我不确定这个新版本(几天前发布的)是否有bug。所以,我想知道如何修复这个错误,或者我是否应该直接使用RESTAPI移动(如果您有一个示例代码,那就太好了!!)。谢谢你

    这是完整的代码:

    string ClassSiteUrl = "https://***********.sharepoint.com/sites/*******";
    string AdminSiteUrl = "https://************-admin.sharepoint.com";
    
    string clientId = "*********************"; //e.g. 01e54f9a-81bc-4dee-b15d-e661ae13f382
    string clientSecret = @"*********************";
    string tenantID = "*********************";
    
    var pwd = "*********************";
    var username = "*********************";
    
    var authManager = new OfficeDevPnP.Core.AuthenticationManager();
    ClientContext context = authManager.GetSharePointOnlineAuthenticatedContextTenant(AdminSiteUrl, username, pwd);
    Tenant tenant = new Tenant(context);
    
    GroupCreationParams optionalParams = new GroupCreationParams(tenant.Context);
    optionalParams.Description = "description";
    optionalParams.CreationOptions = new string[] { "SharePointKeepOldHomepage" };
    
    tenant.CreateGroupForSite(ClassSiteUrl, "*********************", "*********************", true, optionalParams);
    context.ExecuteQuery();
    
    //get group id
    ClientContext classicalsitectx = authManager.GetSharePointOnlineAuthenticatedContextTenant(ClassSiteUrl, username, pwd);
    classicalsitectx.Load(classicalsitectx.Site);
    classicalsitectx.ExecuteQuery();
    var groupid = classicalsitectx.Site.GroupId.ToString(); 
    
    // Link group to a team
    IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
        .Create(clientId)
        .WithTenantId(tenantID)
        .WithClientSecret(clientSecret)
        .Build();
    
    ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
    GraphServiceClient graphClient = new GraphServiceClient(authProvider);
    
    try
    {
    
        var team = new Team
        {
            MemberSettings = new TeamMemberSettings
            {
                AllowCreateUpdateChannels = true
            },
            MessagingSettings = new TeamMessagingSettings
            {
                AllowUserEditMessages = true,
                AllowUserDeleteMessages = true
            },
            FunSettings = new TeamFunSettings
            {
                AllowGiphy = true,
                GiphyContentRating = GiphyRatingType.Strict
            },
            ODataType = null
        };
    
        await graphClient.Groups[groupid].Team
            .Request()
            .PutAsync(team);
    }
    catch (ServiceException e)
    {
        Console.WriteLine("This program is expected to throw WebException on successful run." +
                            "\n\nException Message :" + e.Message);
    }
    catch (Exception ex)
    {
    
        Console.WriteLine("This program is expected to throw WebException on successful run." +
                           "\n\nException Message :" + ex.Message);
    }
    
    这是完整的代码:

    string ClassSiteUrl = "https://***********.sharepoint.com/sites/*******";
    string AdminSiteUrl = "https://************-admin.sharepoint.com";
    
    string clientId = "*********************"; //e.g. 01e54f9a-81bc-4dee-b15d-e661ae13f382
    string clientSecret = @"*********************";
    string tenantID = "*********************";
    
    var pwd = "*********************";
    var username = "*********************";
    
    var authManager = new OfficeDevPnP.Core.AuthenticationManager();
    ClientContext context = authManager.GetSharePointOnlineAuthenticatedContextTenant(AdminSiteUrl, username, pwd);
    Tenant tenant = new Tenant(context);
    
    GroupCreationParams optionalParams = new GroupCreationParams(tenant.Context);
    optionalParams.Description = "description";
    optionalParams.CreationOptions = new string[] { "SharePointKeepOldHomepage" };
    
    tenant.CreateGroupForSite(ClassSiteUrl, "*********************", "*********************", true, optionalParams);
    context.ExecuteQuery();
    
    //get group id
    ClientContext classicalsitectx = authManager.GetSharePointOnlineAuthenticatedContextTenant(ClassSiteUrl, username, pwd);
    classicalsitectx.Load(classicalsitectx.Site);
    classicalsitectx.ExecuteQuery();
    var groupid = classicalsitectx.Site.GroupId.ToString(); 
    
    // Link group to a team
    IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
        .Create(clientId)
        .WithTenantId(tenantID)
        .WithClientSecret(clientSecret)
        .Build();
    
    ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
    GraphServiceClient graphClient = new GraphServiceClient(authProvider);
    
    try
    {
    
        var team = new Team
        {
            MemberSettings = new TeamMemberSettings
            {
                AllowCreateUpdateChannels = true
            },
            MessagingSettings = new TeamMessagingSettings
            {
                AllowUserEditMessages = true,
                AllowUserDeleteMessages = true
            },
            FunSettings = new TeamFunSettings
            {
                AllowGiphy = true,
                GiphyContentRating = GiphyRatingType.Strict
            },
            ODataType = null
        };
    
        await graphClient.Groups[groupid].Team
            .Request()
            .PutAsync(team);
    }
    catch (ServiceException e)
    {
        Console.WriteLine("This program is expected to throw WebException on successful run." +
                            "\n\nException Message :" + e.Message);
    }
    catch (Exception ex)
    {
    
        Console.WriteLine("This program is expected to throw WebException on successful run." +
                           "\n\nException Message :" + ex.Message);
    }
    

    我使用的是Graph API SDK 3.1.0。尝试在团队对象中设置ODataType=null

                var team = new GraphApi.Team
                {      
                    MemberSettings = new GraphApi.TeamMemberSettings
                    {
                        AllowCreateUpdateChannels = true,
                        ODataType = null
                    },
                    MessagingSettings = new GraphApi.TeamMessagingSettings
                    {
                        AllowUserEditMessages = true,
                        AllowUserDeleteMessages = true,
                        ODataType = null
                    },
                    FunSettings = new GraphApi.TeamFunSettings
                    {
                        AllowGiphy = true,
                        GiphyContentRating = GraphApi.GiphyRatingType.Strict,
                        ODataType = null
                    },
                    ODataType = null
                };
    

    我使用的是Graph API SDK 3.1.0。尝试在团队对象中设置ODataType=null

                var team = new GraphApi.Team
                {      
                    MemberSettings = new GraphApi.TeamMemberSettings
                    {
                        AllowCreateUpdateChannels = true,
                        ODataType = null
                    },
                    MessagingSettings = new GraphApi.TeamMessagingSettings
                    {
                        AllowUserEditMessages = true,
                        AllowUserDeleteMessages = true,
                        ODataType = null
                    },
                    FunSettings = new GraphApi.TeamFunSettings
                    {
                        AllowGiphy = true,
                        GiphyContentRating = GraphApi.GiphyRatingType.Strict,
                        ODataType = null
                    },
                    ODataType = null
                };
    


    从昨天(4月17日)起,我收到了与上述相同的回复。创建一个团队或频道以前是有效的。顺便说一句,MSFT昨天发布了Graph API更新,因此认为这可能会引起问题。我正在等待MSFT支持部门对verifyMSFT的回复,因为我的应用程序正在运行。您好,我仍然收到相同的错误。我使用的是3.3DLL版本。您是直接使用C#还是rest api?通过C#代码使用3.1,0版,与上面的代码类似,但是我为每个对象(包括团队对象本身)设置ODataType=null。IE var team=new GraphApi.team{MemberSettings=new GraphApi.TeamMemberSettings{AllowCreateUpdateChannels=true,ODataType=null}…您好,我已通过C#降级到3.1.0。我的回答是完整代码:)比您高!我从昨天(4月17日)起收到与上述相同的回复。创建一个团队或频道以前是有效的。顺便说一句,MSFT昨天发布了Graph API更新,因此认为这可能会导致问题。我正在等待MSFT支持部门对verifyMSFT的响应,因为我的应用程序现在正在工作。您好,我仍然收到相同的错误。我使用的是3.3 DLL版本。您使用的是C#还是rest API直接使用3.1,0版本,通过类似于您上面的c#代码,但是我为每个对象(包括团队对象本身)设置了ODataType=null。即var Team=new GraphApi.Team{MemberSettings=new GraphApi.TeamMemberSettings{AllowCreateUpdateChannels=true,ODataType=null}…您好,我已通过C#降级到3.1.0。我用完整代码回答了这个问题:)而不是您!您好,Phat,我仍然收到相同的错误。此外,我发现您使用的是Graph.Team。改为使用Microsoft.Graph.Team是否正确?代码:BadGateway消息:无法执行后端请求。内部错误:AdditionalData:请求id:e2fd9062-b737-4acf-b82f-be0a113cb62a日期:2020-04-19T17:39:21 ClientRequestId:e2fd9062-b737-4acf-b82f-be0a113cb62aGraphApi在我的上述代码中是Microsoft.GraphApi的别名,因此它与上面使用Microsoft.Graph.Net SDK v3测试的相同。最初每个元素的ODataType无效。修改为以下空团队对象成功。var Team=new Team{ODataType=null};如果恢复到v3.1或使用我提到的解决方法成功,请将此问题标记为已回答。此外,您可以在上打开问题。请打开问题(前面评论中的链接)并共享复制已公开问题的步骤。你好,Phat,我仍然收到相同的错误。此外,我发现您使用的是Graph.Team。改为使用Microsoft.Graph.Team是否正确?代码:BadGateway消息:无法执行后端请求。内部错误:附加数据:请求id:e2fd9062-b737-4acf-b82f-be0a113cb62a date:2020-04-19T17:39:21客户端问题ID:e2fd9062-b737-4acf-b82f-be0a113cb62aGraphApi在我上面的代码中是Microsoft.GraphApi的别名,因此它是上面使用Microsoft.Graph.Net SDK v3.3测试的同一个。最初,每个元素的ODataType都无效。修改以下空团队对象成功essful.var team=new team{ODataType=null};如果成功恢复到v3.1或使用我提到的解决方法,请将此问题标记为已回答。此外,您可以在上打开问题。请打开问题(前面评论中的链接)并共享有关已公开问题的复制步骤。请尝试将ODataType=null添加到团队对象中的每个对象中,也可以按照上面的回答尝试将ODataType=null添加到团队对象中的每个对象中,也可以按照上面的回答