Sample python code for Account Linking in Amazon Alexa

老子叫甜甜 提交于 2020-05-14 12:11:59

问题


Where can i find the sample Python code for Account linking in Amazon Alexa. I was only able to get the documentation here.

https://developer.amazon.com/docs/account-linking/understand-account-linking.html

Please help me !!


回答1:


Account linking works the same way for all languages and you should be familiar with OAuth2 to configure account linking in developer portal.

Users can link account in two ways:

  1. From the skill detail card in the Alexa app while enabling the skill.
  2. From a link account card in the Alexa app after making a request that requires authentication.

When you link an account with your skill, every subsequent request from the skill will include an access token. You can then use this accessToken to get associated data for linked account.

"session": {
        "new": true,
        "sessionId": "amzn1.echo-api.session.xxxxxxxxxxx",
        "application": {
            "applicationId": "amzn1.ask.skill.xxxxxxxxxx"
        },
        "user": {
            "userId": "amzn1.ask.account.xxxxxxx",
            "accessToken": "xxxxxxxxxxxxxx"

For an authenticated usecase, always check whether the accessToken is available and when there is no accessToken in the request that means that the user is not authenticated and you can send the user an Account Link Card. Except for the code to send an Account Link card there is no coding involved in link-an-account process.

To send Account Link Card:

In your response JSON include LinkAccount card

...
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak> Please link your account </speak>"
            },
            "card": {
                "type": "LinkAccount"
            }
...



回答2:


To send the Account Link card in Python…

from ask_sdk_model.ui import Card

…

handler_input.response_builder.set_card(Card('LinkAccount'))


来源:https://stackoverflow.com/questions/51358106/sample-python-code-for-account-linking-in-amazon-alexa

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