私は何か明白なものを紛失しているに違いありません。ベータAPI https://graph.microsoft.com/beta/invitations(APIの参照:https://graph.microsoft.io/en-us/docs/api-reference/beta/api/invitation_post)に投稿する場合は:{ "コード": "ないUnknownError"、 "メッセージ": ""、 "innerError"、私はUnknownError calling/beta/invitations
{ "エラー" を取得します:{ "要求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();
}
}
}
ありがとう!私は他の/ベータコマンドをうまくやることができます。たとえば、https://graph.microsoft.com/beta/usersを取得すると、テナントのユーザーリストが期待どおりに返されます。
ログに基づいて-Dan
あなたはJSONを期待することを伝えるためのContent-Typeヘッダ\tを送信している、ことができますか?この言語に慣れていないので、request.contentがそのエンコーディングとともにそれを設定しているかどうかはわかりません。 – bradenkeith
"request.Content = new StringContent ....."を開始する行の最後にそこにあります。 – spalt
同じリクエストをグラフエクスプローラで使用しようとすると、同じエラーか別のものが表示されますか?これは500エラーですか?私は誰かにトレースログを調べてエラーを理解するように頼んだ。 –