最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

无法读取,页面未定义SDK的特性“getMonetizationServiceClient”

IT培训 admin 3浏览 0评论

无法读取,页面未定义SDK的特性“getMonetizationServiceClient”

我想在技能采购添加到我用下面的代码Alexa的技巧:

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === "LaunchRequest";
    },
    handle(handlerInput){
        console.log("In LaunchRequest");

    const locale = handlerInput.requestEnvelope.request.locale;
    const ms = handlerInput.serviceClientFactory.getMonetizationServiceClient();

    return ms.getInSkillProducts(locale).then(function(result) {
      // Code to handle result.inSkillProducts goes here
       const totalProducts = result.inSkillProducts.length;
       const purchasableProducts = result.inSkillProducts.filter(record => record.purchasable == 'PURCHASABLE');
       const entitledProducts = result.inSkillProducts.filter(record => record.entitled == 'ENTITLED');

       return handlerInput.responseBuilder
        .speak('Found total ' + result.inSkillProducts.length + ' products of which ' + purchasableProducts.length + ' are purchasable and ' + entitledProducts.length + ' are entitled.')
        .getResponse();
    });
    },
};

当我运行的代码,我收到以下错误信息:

Response:
{
  "errorMessage": "Cannot read property 'getMonetizationServiceClient' of undefined",
  "errorType": "TypeError",
  "stackTrace": [
    "Object.handle (/var/task/index.js:16:50)",
    "GenericHandlerAdapter.<anonymous> (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:63:47)",
    "step (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:44:23)",
    "Object.next (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:25:53)",
    "/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:19:71",
    "new Promise (<anonymous>)",
    "__awaiter (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:15:12)",
    "GenericHandlerAdapter.execute (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:61:16)",
    "GenericRequestDispatcher.<anonymous> (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:173:58)",
    "step (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:44:23)"
  ]
}

我已经使用来自Alexa的SDK网站可以在这里找到的代码:.html#getinskillproducts。有人能告诉我什么错误或如何解决呢?提前致谢。

回答如下:

如果您分享您的出口部分,我可能能够进一步帮助。如果使用下面的代码定制Alexa的技能建设者:

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers()

要么

exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers()

然后你只需要添加.withApiClient(new Alexa.DefaultApiClient())

例如您的出口可能是这样的:

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    CancelResponseHandler,
    LaunchRequestHandler,
    HelloWorldIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .lambda();`

我发现,从下面的问题该解决方案:https://github/alexa/alexa-skills-kit-sdk-for-nodejs/issues/356

无法读取,页面未定义SDK的特性“getMonetizationServiceClient”

我想在技能采购添加到我用下面的代码Alexa的技巧:

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === "LaunchRequest";
    },
    handle(handlerInput){
        console.log("In LaunchRequest");

    const locale = handlerInput.requestEnvelope.request.locale;
    const ms = handlerInput.serviceClientFactory.getMonetizationServiceClient();

    return ms.getInSkillProducts(locale).then(function(result) {
      // Code to handle result.inSkillProducts goes here
       const totalProducts = result.inSkillProducts.length;
       const purchasableProducts = result.inSkillProducts.filter(record => record.purchasable == 'PURCHASABLE');
       const entitledProducts = result.inSkillProducts.filter(record => record.entitled == 'ENTITLED');

       return handlerInput.responseBuilder
        .speak('Found total ' + result.inSkillProducts.length + ' products of which ' + purchasableProducts.length + ' are purchasable and ' + entitledProducts.length + ' are entitled.')
        .getResponse();
    });
    },
};

当我运行的代码,我收到以下错误信息:

Response:
{
  "errorMessage": "Cannot read property 'getMonetizationServiceClient' of undefined",
  "errorType": "TypeError",
  "stackTrace": [
    "Object.handle (/var/task/index.js:16:50)",
    "GenericHandlerAdapter.<anonymous> (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:63:47)",
    "step (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:44:23)",
    "Object.next (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:25:53)",
    "/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:19:71",
    "new Promise (<anonymous>)",
    "__awaiter (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:15:12)",
    "GenericHandlerAdapter.execute (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:61:16)",
    "GenericRequestDispatcher.<anonymous> (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:173:58)",
    "step (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:44:23)"
  ]
}

我已经使用来自Alexa的SDK网站可以在这里找到的代码:.html#getinskillproducts。有人能告诉我什么错误或如何解决呢?提前致谢。

回答如下:

如果您分享您的出口部分,我可能能够进一步帮助。如果使用下面的代码定制Alexa的技能建设者:

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers()

要么

exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers()

然后你只需要添加.withApiClient(new Alexa.DefaultApiClient())

例如您的出口可能是这样的:

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    CancelResponseHandler,
    LaunchRequestHandler,
    HelloWorldIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .lambda();`

我发现,从下面的问题该解决方案:https://github/alexa/alexa-skills-kit-sdk-for-nodejs/issues/356

发布评论

评论列表 (0)

  1. 暂无评论