2017-01-14 46 views
0

我必须错过一些明显的东西。当发布到测试API https://graph.microsoft.com/beta/invitations(API参考:https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post),我得到UnknownError致电/测试版/邀请

{ “错误”:{ “代码”: “不明错误”, “消息”: “”, “innerError” :{ “请求ID”: “e41b0eab-c39c-4cf8-9034-341c81fc722c”, “日期”: “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\": \"[email protected]\",\"inviteRedirectUrl\": \"https://MYWEBSITE.COM\"}", Encoding.UTF8, "application/json"); 

      HttpResponseMessage response = await http.SendAsync(request); 
      return await response.Content.ReadAsStringAsync(); 
     } 
    } 

} 

谢谢!我可以做其他/ beta命令就好了。例如GETting https://graph.microsoft.com/beta/users按照预期在我的租户中返回用户列表。

-Dan

+0

你发送的Content-Type \t头,告诉它期待JSON?不熟悉这种语言,所以不确定request.content是否与其编码一起设置。 – bradenkeith

+0

它在那里,在开始“request.Content = new StringContent .....”的线条的最后端 – spalt

+0

如果使用图形浏览器尝试相同的请求,是否会得到相同的错误或不同的内容?这是500错误吗?我让某人查看跟踪日志以了解错误。 –

回答

0

基于日志,您收到一个401错误响应,这意味着调用者未被授予所需的权限调用API。你需要遵循这里的指导:https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post这表明你需要Directory.ReadWrite.All或User.ReadWrite.All(尽管我不确定后者是否有效或现在可用)。

我们还提交了一个错误来解决这个错误信息(抱歉 - 我们需要在这里做得更好)。

希望这有助于

+0

感谢您的快速响应!权限绝对是问题。事实证明我已经在门户网站中授予了正确的权限,但我没有点击“授予权限”按钮。杜尔。 thx再次。 – spalt

+0

丹,为了记录,这个邀请管理者实际上并没有通过电子邮件邀请用户,对吗?实际发送电子邮件是我们的责任? – spalt

+0

没关系,我在邀请管理器文档中找到对“sendInvitationMessage”的引用:“true”。好像你在invitation_post文件中应该有这样的内容,但是我知道什么:) – spalt

相关问题