gpt4 book ai didi

c# - [Azure 数据目录] : Read the data from Azure data catalog glossary Unauthorized error?

转载 作者:行者123 更新时间:2023-12-03 05:52:13 25 4
gpt4 key购买 nike

我尝试将 Excel 数据发布到 azure 数据目录中。我是用控制台应用程序编写的。

我的代码是

static void Main()
{
string DefaultCatalog = "DefaultCatalog";
string DefaultGlossary = "DefaultGlossary";
string fullUri = string.Format("https://api.azuredatacatalog.com/catalogs/{0}/glossaries/{1}/terms?api-version=2016-03-30",
DefaultCatalog, DefaultGlossary);
HttpWebRequest request = WebRequest.Create(fullUri) as HttpWebRequest;
request.KeepAlive = true;
request.Method = "GET";
request.Accept = "application/json;adc.metadata=full";
request.Headers.Add("Authorization", AccessToken().Result.CreateAuthorizationHeader());
request.AllowAutoRedirect = false;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response != null && response.StatusCode == HttpStatusCode.Redirect)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var itemPayload = reader.ReadToEnd();
JToken terms;
JObject.Parse(itemPayload).TryGetValue("value", out terms);
if (terms != null)
{
var r = JsonConvert.DeserializeObject<JArray>(terms.ToString());
}
}
}
}

static async Task<AuthenticationResult> AccessToken()
{
string clientId = "MyClientId";
string client_secret = "MyClientSecret";
string tenentId = "MytenentId";
if (_authResult == null)
{
// Resource Uri for Data Catalog API
string resourceUri = "https://api.azuredatacatalog.com/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
string authorityUri = "https://login.windows.net/MytenentId/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);

_authResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Always));

//ClientCredential cc = new ClientCredential(clientId, client_secret);
//_authResult = await authContext.AcquireTokenAsync(resourceUri, cc);

}
return _authResult;
}

我想从我的 azure 数据目录中获取术语表列表。但它总是返回未经授权的错误。“远程服务器返回错误:(403) 禁止。”

我的错误是

enter image description here

最佳答案

您需要使用以下方法来获取正确的 token :字符串authorityUri =“https://login.windows.net/common/oauth2/authorize”;

希望这有帮助,莫妮卡

关于c# - [Azure 数据目录] : Read the data from Azure data catalog glossary Unauthorized error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46482329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com