TencentCloud / tencentcloud-sdk-nodejs

Tencent Cloud API 3.0 SDK for NodeJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用文档中CDN刷新URL接口例子报错

slgluo opened this issue · comments

commented

错误信息:
[TencentCloudSDKException]message:The specified api version=‘2018-06-06’ does not exist in service=‘cvm’.

代码如下:

    const clientConfig = {
      credential: {
        secretId: secretId || process.env.SECRET_ID,
        secretKey: secretKey || process.env.SECRET_KEY,
      },
      region: "",
      profile: {
        httpProfile: {
          endpoint: "cvm.tencentcloudapi.com",
        },
      },
    };

    const client = new CdnClient(clientConfig);

    if(!paths && !dirs) {
      throw new Error('--path和--dir为空,两者必须选一')
    } else if (paths && paths.length > 0) {
      const params = {
        "Urls": paths
      };

      client.PurgeUrlsCache(params).then(
        data => {
          logger.info("刷新URL成功")
          logger.info(data)
        },
        err => {
          logger.error("刷新URL失败")
          logger.error(err)
        }
      );
    } else if (dirs && dirs.length > 0) {
      const params = {
        "Paths": dirs,
        "FlushType": "flush"
      };

      client.PurgePathCache(params).then(
        data => {
          logger.info("刷新目录成功")
          logger.info(data)
        },
        err => {
          logger.error("刷新目录失败")
          logger.error(err)
        }
      );
    }

调用cdn的接口需要使用cdn的域名
endpoint: "cvm.tencentcloudapi.com",
这里改为
endpoint: "cdn.tencentcloudapi.com",
即可