我必須錯過一些明顯的東西。當發佈到測試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
你發送的Content-Type \t頭,告訴它期待JSON?不熟悉這種語言,所以不確定request.content是否與其編碼一起設置。 – bradenkeith
它在那裏,在開始「request.Content = new StringContent .....」的線條的最後端 – spalt
如果使用圖形瀏覽器嘗試相同的請求,是否會得到相同的錯誤或不同的內容?這是500錯誤嗎?我讓某人查看跟蹤日誌以瞭解錯誤。 –