Access denied due to invalid subscription key (Face API)

ε祈祈猫儿з 提交于 2019-12-29 06:44:09

问题


I am having trouble using Microsoft Face API. Below is my sample request:

curl -v -X POST "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: 1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd" --data-ascii "{\"url\":\"http://www.mrbeantvseries.co.uk/bean3.jpg\"}"

I use the subscription id from my cognitive services account and I got below response:

{
  "error": {
    "code": "Unspecified",
    "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."
  }
}

Not sure if I've missed out anything there. Can someone help me on this? Very much appreciated.


回答1:


It appears that you've entered your Azure subscription ID instead? In the Azure portal, you can find the API key under 'Keys', shown below:

It will be a 32-digit hexadecimal number, no hyphens.




回答2:


I ran into the same problem. I read the API documentation and it states the following.

You must use the same region in your REST API call as you used to obtain your subscription keys.

First, you must find the location of your subscription. In order to find the location of your subscription region, you must go to Cognitive Services -> Properties under the Label Location, you will find your subscription region. See below.

Second you must find the correct endpoint to make the call to. For example, if I want to make a call to the Computer Vision API, My location is East US, I will use either key 1 or 2, then I will use the following endpoint East US - https://eastus.api.cognitive.microsoft.com/face/v1.0/detect

You will now be able to have access to the API.




回答3:


I had faced the same issue, it seems like there is some problem with the keys generated newly. To fix this you can actually add your endpoint as well, when you create the object for IFaceServiceClient. You can see the code below.

private readonly IFaceServiceClient faceServiceClient = new FaceServiceClient("your key", "Your endpoint");




回答4:


CesarB is correct. You must create a Resource of Cognitive Service in Azure first and then get the subscription key from it. the region is not always 'westus', it really depends on what region you select when you created the resource. You can also check it on the endpoint of overview of the Resource




回答5:


Endpoint https://westeurope.api.cognitive.microsoft.com/face/v1.0

Endpoint and the subscription key must be consistent.

look at Microsoft Overview for this info!



来源:https://stackoverflow.com/questions/42123633/access-denied-due-to-invalid-subscription-key-face-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!