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 !!
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 !!
We can use the function get_account_linking_access_token()
from ASK SDK for python, to get the user token for account linking
and store in the variable account_linking_token
. Use the token to fetch the user data if account linking has been done, as shown below:
from ask_sdk_model.ui import SimpleCard
speech_output = ''
if account_linking_token is not None:
url = "https://api.amazon.com/user/profile?access_token{}"\
.format(account_linking_token)
user_data = requests.get(url).json()
# retrieve the required user info here and populate output
# speech_output = ...
else:
# output msg when account linking is not done
# speech_output = ...
# return this response from the intent handler function
response = handler_input.response_builder
.speak(speech_output)
.ask(reprompt)
.set_card(SimpleCard(speech_output))
.response
Account linking works the same way for all languages and you should be familiar with
OAuth2
to configure account linking in developer portal.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.For an authenticated usecase, always check whether the
accessToken
is available and when there is noaccessToken
in the request that means that the user is not authenticated and you can send the user anAccount Link Card
. Except for the code to send anAccount Link card
there is no coding involved in link-an-account process.To send Account Link Card:
In your response JSON include
LinkAccount
card