美文网首页
06 云函数中调用腾讯云SDK

06 云函数中调用腾讯云SDK

作者: 古月量化 | 来源:发表于2020-07-14 22:03 被阅读0次

    1、在“微信开发工具”的某云函数上点击右键,选择“在外部终端窗口”打开
    2、在函数命令行运行“npm install tencentcloud-sdk-nodejs --save”
    3、上传并部署云函数(云端安装依赖)
    4、修改官方文档 demo 中的参数即可运行了

    const tencentcloud = require("tencentcloud-sdk-nodejs");
    
    const NlpClient = tencentcloud.nlp.v20190408.Client;
    const models = tencentcloud.nlp.v20190408.Models;
    const Credential = tencentcloud.common.Credential;
    const ClientProfile = tencentcloud.common.ClientProfile;
    const HttpProfile = tencentcloud.common.HttpProfile;
    let cred = new Credential("secretid", "secretkey");
    let httpProfile = new HttpProfile();
    httpProfile.endpoint = "nlp.tencentcloudapi.com";
    let clientProfile = new ClientProfile();
    clientProfile.httpProfile = httpProfile;
    let client = new NlpClient(cred, "", clientProfile);
    let req = new models.WordEmbeddingRequest();
    let params = '{\"Text\":\"中国\"}'
    req.from_json_string(params);
    
    client.WordEmbedding(req, function(errMsg, response) {
        if (errMsg) {
            console.log(errMsg);
            return;
        }
        console.log(response.to_json_string());
    });
    

    相关文章

      网友评论

          本文标题:06 云函数中调用腾讯云SDK

          本文链接:https://www.haomeiwen.com/subject/disqhktx.html