未知错误调用 /beta/invitations
UnknownError calling /beta/invitations
我一定是遗漏了一些明显的东西。发布到测试版 API https://graph.microsoft.com/beta/invitations (api ref: https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post) 时,我得到
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"request-id": "e41b0eab-c39c-4cf8-9034-341c81fc722c",
"date": "2017-01-14T19:26:55"
}
}
}
这是我的代码:
namespace ConsoleApplication1
{
public class Program
{
static void Main(string[] args)
{
GraphClient g = new GraphClient();
Console.WriteLine(g.SendPost(g.authContext, g.credential).Result);
}
}
public class GraphClient
{
public AuthenticationContext authContext;
public ClientCredential credential;
public GraphClient()
{
this.authContext = new AuthenticationContext("https://login.microsoftonline.com/MYTENANT.onmicrosoft.com");
this.credential = new ClientCredential("MYCLIENTID", "MYCLIENTSECRET");
}
public async Task<string> SendPost(AuthenticationContext authContext, ClientCredential credential)
{
AuthenticationResult result = await authContext.AcquireTokenAsync("https://graph.microsoft.com", credential);
HttpClient http = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://graph.microsoft.com/beta/invitations");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
request.Content = new StringContent("{\"invitedUserEmailAddress\": \"MYEMAIL@MYDOMAIN.COM\",\"inviteRedirectUrl\": \"https://MYWEBSITE.COM\"}", Encoding.UTF8, "application/json");
HttpResponseMessage response = await http.SendAsync(request);
return await response.Content.ReadAsStringAsync();
}
}
}
谢谢!我可以很好地执行其他 /beta 命令。例如,按预期在我的租户中获取 https://graph.microsoft.com/beta/users returns 用户列表。
-丹
根据日志,您收到了 401 错误响应,这意味着调用者未被授予调用 API 所需的权限。您需要遵循此处的指导:https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post,这表明您需要 Directory.ReadWrite.All 或 User.ReadWrite.All(尽管我不确定后者是否有效或现在是否可用)。
我们还提交了一个错误来修复此错误消息(对此感到抱歉 - 我们确实需要在这方面做得更好)。
希望对您有所帮助,
我一定是遗漏了一些明显的东西。发布到测试版 API https://graph.microsoft.com/beta/invitations (api ref: https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post) 时,我得到
{ "error": { "code": "UnknownError", "message": "", "innerError": { "request-id": "e41b0eab-c39c-4cf8-9034-341c81fc722c", "date": "2017-01-14T19:26:55" } } }
这是我的代码:
namespace ConsoleApplication1
{
public class Program
{
static void Main(string[] args)
{
GraphClient g = new GraphClient();
Console.WriteLine(g.SendPost(g.authContext, g.credential).Result);
}
}
public class GraphClient
{
public AuthenticationContext authContext;
public ClientCredential credential;
public GraphClient()
{
this.authContext = new AuthenticationContext("https://login.microsoftonline.com/MYTENANT.onmicrosoft.com");
this.credential = new ClientCredential("MYCLIENTID", "MYCLIENTSECRET");
}
public async Task<string> SendPost(AuthenticationContext authContext, ClientCredential credential)
{
AuthenticationResult result = await authContext.AcquireTokenAsync("https://graph.microsoft.com", credential);
HttpClient http = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://graph.microsoft.com/beta/invitations");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
request.Content = new StringContent("{\"invitedUserEmailAddress\": \"MYEMAIL@MYDOMAIN.COM\",\"inviteRedirectUrl\": \"https://MYWEBSITE.COM\"}", Encoding.UTF8, "application/json");
HttpResponseMessage response = await http.SendAsync(request);
return await response.Content.ReadAsStringAsync();
}
}
}
谢谢!我可以很好地执行其他 /beta 命令。例如,按预期在我的租户中获取 https://graph.microsoft.com/beta/users returns 用户列表。
-丹
根据日志,您收到了 401 错误响应,这意味着调用者未被授予调用 API 所需的权限。您需要遵循此处的指导:https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post,这表明您需要 Directory.ReadWrite.All 或 User.ReadWrite.All(尽管我不确定后者是否有效或现在是否可用)。
我们还提交了一个错误来修复此错误消息(对此感到抱歉 - 我们确实需要在这方面做得更好)。
希望对您有所帮助,