【问题标题】:Alexa Remainder API (REST API) - Invalid bearer tokenAlexa Remainder API (REST API) - 无效的不记名令牌
【发布时间】:2020-03-04 12:08:24
【问题描述】:

我正在尝试通过 POSTMan 向我的技能发送警报/剩余信息。

选项 1: 范围为“alexa:skill_messaging”的身份验证令牌 API

POST /auth/o2/token HTTP/1.1
Host: api.amazon.com
Content-Type: application/x-www-form-urlencoded
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 2ae7afa3-c3f8-493f-b6e3-2db1e44e3a17,a4e45e8e-d0eb-4b3f-a612-e7d1959fdbe6
Host: api.amazon.com
Accept-Encoding: gzip, deflate
Content-Length: 236
Connection: keep-alive
cache-control: no-cache

grant_type=client_credentials&client_id=******************&client_secret=***********17a4f7b348982bdb4&scope=alexa%3Askill_messaging

截图:

选项 2: 具有作用域的身份验证令牌 API "alexa::alerts:reminders:skill:readwrite"

POST /auth/o2/token HTTP/1.1
Host: api.amazon.com
Content-Type: application/x-www-form-urlencoded
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 2ae7afa3-c3f8-493f-b6e3-2db1e44e3a17,c6765f77-6e35-419f-b614-780dae20ad4e
Host: api.amazon.com
Accept-Encoding: gzip, deflate
Content-Length: 236
Connection: keep-alive
cache-control: no-cache

grant_type=client_credentials&client_id=**************************&client_secret=************************&scope=alexa%3A%3Aalerts%3Areminders%3Askill%3Areadwrite

第 2 步: 使用 Scope 生成的令牌提交警报请求 "alexa:skill_messaging" 获取 Invalide Bearer token

如果我遗漏了什么,请告诉我,以及在哪里可以找到 Alexa Authenictaion Token API 的不同范围

【问题讨论】:

    标签: alexa alexa-skills-kit alexa-app


    【解决方案1】:

    很遗憾,

    “这是 Reminders API 的限制 - 您需要使用会话内访问令牌来创建提醒。您也可以在会话外运行 GET、UPDATE 和 DELETE 操作,因此请检查this out了解更多信息。”

    只有与设备通话才能获得会话中访问令牌以创建提醒。

    会话外 - 获取技能创建的提醒(技能消息 API):

        const IncomingMessageHandler = {
            canHandle(handlerInput) {
                const request = handlerInput.requestEnvelope.request;
                return request.type === 'Messaging.MessageReceived'
            },
            async handle(handlerInput) {
                const { requestEnvelope, context } = handlerInput;
                console.log(`Message content: ${JSON.stringify(requestEnvelope.request.message)}`);
    
                try {
                  const client = handlerInput.serviceClientFactory.getReminderManagementServiceClient();
                  const remindersResponse = await client.getReminders();
                  console.log(JSON.stringify(remindersResponse));
                } catch (error) {
                  console.log(`error message: ${error.message}`);
                  console.log(`error stack: ${error.stack}`);
                  console.log(`error status code: ${error.statusCode}`);
                  console.log(`error response: ${error.response}`);
                }
    
                context.succeed();
            }
        }
    

    https://developer.amazon.com/docs/smapi/alexa-reminders-api-reference.html#in-session-and-out-of-session-behavior-for-alexa-reminders-api

    https://forums.developer.amazon.com/questions/196445/reminders-can-only-be-created-in-session.html#answer-196860

    https://developer.amazon.com/pt-BR/docs/alexa/smapi/skill-messaging-api-reference.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-08
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2021-10-04
      相关资源
      最近更新 更多