C# 的图表 API:尝试在 Office 365 上创建团队时的 BadGateway 结果
Graph API for C#: BadGateway result when try to create a Team on Office 365
几天以来,我一直在研究一个解决方案,该解决方案在 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
更多评论:
- 执行的用户是网站集管理员(初始化此对象时)
var authManager = new OfficeDevPnP.Core.AuthenticationManager();
ClientContext context = authManager.GetSharePointOnlineAuthenticatedContextTenant(AdminSiteUrl, username, pwd);
Azure中的Client Secret Id和App注册权限如下:
我用来声明 Team 对象的特定版本是 Assembly Microsoft.Graph,Version=3.3.0.0 使用 Nuget。我在使用 3.2.0.0
时遇到同样的问题
我知道可以直接使用 REST API 执行相同的方法,但我不确定这个新版本(几天前发布的)是否有错误。所以,我想知道如何修复这个错误,或者我是否应该直接使用 REST API 移动(如果你有示例代码,那就太好了!!)。感谢你!
这是完整代码:
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
};
几天以来,我一直在研究一个解决方案,该解决方案在 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
更多评论:
- 执行的用户是网站集管理员(初始化此对象时)
var authManager = new OfficeDevPnP.Core.AuthenticationManager();
ClientContext context = authManager.GetSharePointOnlineAuthenticatedContextTenant(AdminSiteUrl, username, pwd);
Azure中的Client Secret Id和App注册权限如下:
我用来声明 Team 对象的特定版本是 Assembly Microsoft.Graph,Version=3.3.0.0 使用 Nuget。我在使用 3.2.0.0
时遇到同样的问题
我知道可以直接使用 REST API 执行相同的方法,但我不确定这个新版本(几天前发布的)是否有错误。所以,我想知道如何修复这个错误,或者我是否应该直接使用 REST API 移动(如果你有示例代码,那就太好了!!)。感谢你!
这是完整代码:
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
};