[Face API]由于订阅密钥无效而拒绝访问。 [英] [Face API] Access denied due to invalid subscription key.

查看:778
本文介绍了[Face API]由于订阅密钥无效而拒绝访问。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:


我正在测试Emotions和Face API。我在https://www.microsoft.com/cognitive-services/en-us/subscriptions门户网站上获得了两个API(面部预览和情感预览)的提示。我没有Emotions API的问题,我用
正确地得到了json以下代码:

 private async Task< string> GetEmotions(StorageFile文件)
{
string responseContent = string.Empty;
using(HttpClient httpClient = new HttpClient())
{
// setup HttpClient
httpClient.BaseAddress = new Uri(EmotionsApiUrl);
httpClient.DefaultRequestHeaders.Add(" Ocp-Apim-Subscription-Key",EmotionsApiKey);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(" application / octet-stream"));

//设置数据对象
HttpContent content = new StreamContent(await file.OpenStreamForReadAsync());
content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(" application / octet-stream");

// make request
HttpResponseMessage response = await httpClient.PostAsync(EmotionsApiUrl,content);

//读取响应并写入视图
responseContent = await response.Content.ReadAsStringAsync();
Debug.WriteLine($" Emotions:{responseContent}");
}
返回responseContent;
}




对于Face API,我的代码几乎相同:

 private async Task< string> GetFaces(StorageFile文件)
{
string responseContent;
using(HttpClient httpClient = new HttpClient())
{
// setup HttpClient
httpClient.BaseAddress = new Uri(FaceApiUrl);
httpClient.DefaultRequestHeaders.Add(" Ocp-Apim-Subscription-Key",FacesApiKey);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(" application / octet-stream"));

//设置数据对象
HttpContent content = new StreamContent(await file.OpenStreamForReadAsync());
content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(" application / octet-stream");

// make request
HttpResponseMessage response = await httpClient.PostAsync(EmotionsApiUrl,content);

//读取响应并写入视图
responseContent = await response.Content.ReadAsStringAsync();
Debug.WriteLine($" Face:{responseContent}");
}
返回responseContent;
}

但在这种情况下,我得到"由于订阅密钥无效而拒绝访问"错误:

 {
" error":
{
" code":" Unauthorized",
" message":"由于订阅密钥无效而拒绝访问。确保您订阅了您要拨打的API,并提供了正确的密钥。"
}
}

我确定我正在使用Face API的正确API密钥,我尝试使用相同结果的主键和辅助键。你知道这是什么问题吗?


解决方案

你好,


很抱歉听到您遇到此问题。  您可以在

验证您的订阅密钥是否适用于Face API测试控制台
。  您是否仍然在测试控制台中遇到订阅密钥问题?


谢谢,


Raymond


Hello:

I'm testing Emotions and Face APIs. I get suscriptions for both APIs (Face Preview and Emotions Preview) in https://www.microsoft.com/cognitive-services/en-us/subscriptions portal. I don't have problems with Emotions API, I get the json correctly with the following code:

private async Task<string> GetEmotions(StorageFile file)
{
    string responseContent = string.Empty;
    using (HttpClient httpClient = new HttpClient())
    {
        //setup HttpClient
        httpClient.BaseAddress = new Uri(EmotionsApiUrl);
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", EmotionsApiKey);
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));

        //setup data object
        HttpContent content = new StreamContent(await file.OpenStreamForReadAsync());
        content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/octet-stream");

        //make request
        HttpResponseMessage response = await httpClient.PostAsync(EmotionsApiUrl, content);

        //read response and write to view
        responseContent = await response.Content.ReadAsStringAsync();
        Debug.WriteLine($"Emotions: {responseContent}");
    }
    return responseContent;
}


For the Face API I have almost same code:

private async Task<string> GetFaces(StorageFile file)
{
    string responseContent;
    using (HttpClient httpClient = new HttpClient())
    {
        //setup HttpClient
        httpClient.BaseAddress = new Uri(FaceApiUrl);
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", FacesApiKey);
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));

        //setup data object
        HttpContent content = new StreamContent(await file.OpenStreamForReadAsync());
        content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/octet-stream");

        //make request
        HttpResponseMessage response = await httpClient.PostAsync(EmotionsApiUrl, content);

        //read response and write to view
        responseContent = await response.Content.ReadAsStringAsync();
        Debug.WriteLine($"Face: {responseContent}");
    }
    return responseContent;
}

But in this case I get "Access denied due to invalid subscription key" error:

{
  "error":
  {
    "code": "Unauthorized",
    "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
  }
}

I'm sure that I'm using the correct API key for Face API, I have tried with primary and secondary keys with the same result. Do you know what is the problem?

解决方案

Hello,

Sorry to hear you ran into this problem.  You can verify your subscription key is working for Face API in the testing console.  Do you still have the trouble with the subscription key in the testing console?

Thank you,

Raymond


这篇关于[Face API]由于订阅密钥无效而拒绝访问。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆