Face API - 在进行人物组PUT操作时出现404错误。

问题描述 投票:0回答:1

我试着用js节点使用face api,但响应总是 "statusCode"。404, "message": "Resource not found"(找不到资源),是不是我在安装的时候忽略了什么?

这是我的代码

const uriBase2 = 'https://myendpoint/face/v1.0/persongroups';

const params = {
    'personGroupId': 'dava12345',
};

const options = {
    uri: uriBase2,
    qs: params,
    method: 'PUT',
    body: '{ "name": "group2", "userData": "user-provided data attached to ", "recognitionModel": "recognition_02" }',
    headers: {
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key' : 'mykey'
    }
};


 request(options, (error, response, body) => {
     if (error) {
       console.log('Error: ', error);
       return;
     }
     let jsonResponse = JSON.stringify(JSON.parse(body), null, '  ');
     console.log('JSON Response\n');
     console.log(jsonResponse);
   });
node.js microsoft-cognitive face-recognition
1个回答
0
投票

更新

我发现了问题。你只是失去了 / 在您的请求网址中,需要添加 params.personGroupId 之后 uriBase.

错误的图片。

enter image description here

正确的图片。

enter image description here

列表personGroup,找到 202006090101 其中创建刚刚。

enter image description here

PRIVIOUS

代码。

const request = require('request');

const uriBase = 'https://ea***s.api.cognitive.microsoft.com/face/v1.0/persongroups';

const params = {
    'personGroupId': 'pan***test',
};

const options = {
    url: uriBase,
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key' : '6e4f6d73***23ddf2f5792'
    }
};

request(options, function(err, res, body) {
    let json = JSON.parse(body);
    console.log(json);
});

图:

enter image description here

详情

  1. 创建项目文件夹,用vscode打开
  2. 创建一个 test.js 文件夹中的文件,粘贴我的测试代码,并替换为 uriBasepersonGroupIdOcp-Apim-Subscription-Key.
  3. 运转 npm i,成功后,再运行 npm install request
  4. 运行 node test.js
© www.soinside.com 2019 - 2024. All rights reserved.