【发布时间】:2025-11-26 19:00:01
【问题描述】:
我尝试使用以下代码在 Office 365 中为组创建别名,但它显示了一些错误。如何解决此问题。我尝试使用服务到服务调用方法。我得到了生成的令牌。如何检查其有效与否?是否可以使用 api 为没有 powershell 选项的组创建别名?如果没有好心的建议我其他选择..
string clientId = "************";
string clientsecret = "******";
string tenantId = "********";
//string resourceUri = "http://office.microsoft.com/outlook/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
var authUri = "https://login.windows.net/" + tenantId + "/oauth2/authorize/";
var RESOURCE_URL = "https://graph.windows.net";
HttpClient client = new HttpClient();
var authContext = new AuthenticationContext(authUri);
var credential = new ClientCredential(clientId: clientId, clientSecret: clientsecret);
var result = authContext.AcquireTokenAsync(RESOURCE_URL, credential).Result;
client.DefaultRequestHeaders.Add("Authorization", "bearer " + result.AccessToken);
string content = @"{
'displayName': 'mailgrouptest',
'groupTypes': ['Unified'],
'mailEnabled': true,
'mailNickname': 'mailalias1',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
当我在控制台中运行此代码时,它会显示这样的错误......是令牌的问题吗?还是租户 ID?
{ "error": { "code": "InvalidAuthenticationToken", "message": "Access token validation failure.", "innerError": {`` "request-id": "*****-***-", "date": "2016-05-25T04:53:08" } } }
请建议我在 api 中为组创建别名
【问题讨论】:
标签: powershell office365api azure-ad-graph-api