How to get an Alexa userId?

非 Y 不嫁゛ 提交于 2019-12-04 00:13:57

You are doing it right. This amzn1.ask.account.[unique-value-here] is in-fact the full userid. You can observe this for yourself by enabling your skill from an Echo, logging several requests to your alexa skill, and observing that the userid between these requests is the same value.

Per the JSON Reference:

userId: A string that represents a unique identifier for the user who made the request. The length of this identifier can vary, but is never more than 255 characters. The userId is automatically generated when a user enables the skill in the Alexa app.

Note: Disabling and re-enabling a skill generates a new identifier.

If you only need to persist user attributes between sessions, this value will be sufficient and you can use it to uniquely identify this user so long as they have the skill enabled.

If you need to link an account, the value you're looking for is accessToken and lives in that same user object following successful account link. Per the same JSON Reference as above:

accessToken: a token identifying the user in another system. This is only provided if the user has successfully linked their account. See Linking an Alexa User with a User in Your System for more details.

Well, turns out I was doing everything correctly (for once). The reason why the userId was literally amzn1.ask.account.[unique-value-here] was because I was testing it on a "Alexa Start Session" test event in the AWS Lambda console. When I asked my Echo Dot to launch the skill, it generated the actual key. Problem solved.

You should try to read the request that is displayed in the Test console of ASK. From there, you can access the different variables that are being sent to your lambda function. Also, you can manipulate or use them as per your requirement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!