小程序调用腾讯云人脸识别创建人员接口调用错误怎么解决?

  • 回答 (1)
  • 关注 (0)
  • 查看 (53)

创建人员的云函数代码如下

const cloud = require('wx-server-sdk') //小程序云开发SDK

const tencentcloud = require("tencentcloud-sdk-nodejs"); //腾讯云API 3.0 SDK

const secret = require('./config.js');

cloud.init({

env: 'test-wsnw3'

}) //云开发初始化

var synCreatePerson = function (url,personname,personid,gender) { //人脸识别API

const IaiClient = tencentcloud.iai.v20180301.Client;

const models = tencentcloud.iai.v20180301.Models;

const Credential = tencentcloud.common.Credential;

const ClientProfile = tencentcloud.common.ClientProfile;

const HttpProfile = tencentcloud.common.HttpProfile;

let cred = new Credential(secret.SecretId, secret.SecretKey); //腾讯云的SecretId和SecretKey,打开config.js文件配置

let httpProfile = new HttpProfile();

httpProfile.endpoint = "iai.tencentcloudapi.com"; //腾讯云人脸识别API接口

let clientProfile = new ClientProfile();

clientProfile.httpProfile = httpProfile;

let client = new IaiClient(cred, "", clientProfile); //调用就近地域

let req = new models.CreatePersonRequest();

let params = '{"GroupId":"1","PersonName":"' + personname + '","PersonId":"' + personid + '","Gender":gender,"Url":"' + url + '"}' //拼接参数

req.from_json_string(params);

return new Promise(function (resolve, reject) { //构造异步函数

client.CreatePerson(req, function (errMsg, response) {

if (errMsg) {

reject(errMsg)

} else {

resolve(response);

}

})

})

}

// 云函数入口函数

exports.main = async (event, context) => {

const fileList = [event.fileID] //读取来自客户端的fileID

console.log("fileID:" + event.fileID, "PersonID:" + event.PersonId, "PersonName:" + event.PersonName, "Gender:" + event.Gender)

const result = await cloud.getTempFileURL({ //向云存储发起读取文件临时地址请求

fileList,

})

console.log("result:" + JSON.stringify(result))

const url = result.fileList[0].tempFileURL

console.log("url:" + url)

datas = await synCreatePerson(result.fileList[0].tempFileURL,event.PersonName,event.PersonId,event.Gender) //调用异步函数,向腾讯云API发起人脸检测请求

return datas

}

调用的时候出现错误

TypeError: Cannot read property 'v20180301' of undefined

at synCreatePerson (/var/user/index.js:8:38)

at EventHandler.exports.main [as realHandler] (/var/user/index.js:45:17)

at <anonymous>

at process._tickCallback (internal/process/next_tick.js:188:7)

应该怎么解决,在线等各位大佬的帮助。

用户5687063用户5687063提问于
鹿鸣回答于

检查下腾讯云node SDK的版本,使用最新版哈。、。

可能回答问题的人

  • 腾讯云计算产品团队

    腾讯云 · 产品团队 (已认证)

    136 粉丝0 提问0 回答
  • Y. Ji

    6 粉丝0 提问1 回答
  • CVM 产品团队

    26 粉丝0 提问7 回答
  • 小仙女和科学家

    9 粉丝0 提问0 回答
  • 怕冷的阳阳

    腾讯云 · 高级工程师 (已认证)

    19 粉丝1 提问0 回答
  • DRRR

    腾讯云 · 产品经理 (已认证)

    6 粉丝0 提问4 回答

扫码关注云+社区

领取腾讯云代金券