JSON出力でユーザーグループの詳細を取得しようとしています。私は出力を得るためにいくつかのHTTPメソッドを参照しましたが、予期したJSON出力の代わりに例外The remote server returned an error: (401) Unauthorized.
が発生します。C#コンソールアプリケーションでMicrosoftグラフエクスプローラを使用するには?
私のコードは、私が認証エラーが存在しているはず
public void GetJSON()
{
string url = string.Format("https://graph.microsoft.com/v1.0/groups");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
webrequest.Method = "GET";
webrequest.ContentType = "application/x-www-form-urlencoded";
webrequest.Headers.Add("Username", "[email protected]");
webrequest.Headers.Add("Password", "mypassword");
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
StreamReader responseStream = new StreamReader(webresponse.GetResponseStream(), enc);
string result = string.Empty;
result = responseStream.ReadToEnd();
webresponse.Close();
return result;
}
です。しかし、私はこれをクリアする方法を知らない? Microsoftグラフエクスプローラで予想される出力を得ることができますが、コンソールアプリケーションでこのエラーが発生します。
誰もがこの例外をクリアする方法を知っていますか?前に、私の方法は、Microsoft Graph APIを使用するための権利ですか?
あなたはIISサーバーにアクセスできますか? –
Microsoft Graph APIへのアクセスを許可している場合、Azure Active Directoryの設定を確認してください。それは役に立つかもしれない –