2017-01-14 47 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

相關問題