简体   繁体   中英

How to get amazon email in an alexa sdk V2 skill

I'm trying to develop an alexa skill and I would like to get the user's email and then compare it to those of a database. I found many examples on the web but they are all written in SDK v1 which is no longer supported. Can anyone help me?

You have to request permission to gather customer information. This can be done within the Alexa developer console. Within your skill go to Build > Permissions you will see a number of items starting with Device Address, Customer Name and then Customer Email. You will need to select this and build your skill.

Now when a user adds your skill they will have the opportunity to give you access to their email address and any other items you have requested.

Once you have permission you can now make a call to the Customer Profile API.

This will be two steps.

First get the access Token:

accessToken = this.event.context.System.apiAccessToken;

It should be noted that when using the token the syntax is:

Bearer < ACCESS_TOKEN > 

Now you can use the token to request the information you are looking for from the API using the following request:

Host: api.amazonalexa.com
Accept: application/json
Authorization: Bearer MQEWY...6fnLok
GET https://api.amazonalexa.com/v2/accounts/~current/settings/Profile.email

This process and addtional information can be found in the developer docs here

@raholling ok, following your instructions and after reading the documentation I wrote this piece of code only that it does not work either on AWS or in the spoken test on alexa developer. What am I doing wrong?
var accessToken = this.event.context.System.apiAccessToken;

Bearer < ACCESS_TOKEN > 

Host: api.amazonalexa.it
Accept: application/json
Authorization: Bearer MQEWY...6fnLok
GET https://api.amazonalexa.com/v2/accounts/~current/settings/Profile.email;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM