<p>帐户链接对所有语言的工作方式相同,您应该熟悉<code>OAuth2</code>以在开发人员门户中配置帐户链接</p>
<blockquote>
<p>Users can link account in two ways:</p>
<ol>
<li>From the skill detail card in the Alexa app while enabling the skill.</li>
<li>From a link account card in the Alexa app after making a request that requires authentication.</li>
</ol>
</blockquote>
<p>当您将帐户与您的技能链接时,来自该技能的每个后续请求都将包含一个访问令牌。然后可以使用此<code>accessToken</code>获取链接帐户的关联数据</p>
<pre><code>"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.xxxxxxxxxxx",
"application": {
"applicationId": "amzn1.ask.skill.xxxxxxxxxx"
},
"user": {
"userId": "amzn1.ask.account.xxxxxxx",
"accessToken": "xxxxxxxxxxxxxx"
</code></pre>
<p>对于经过身份验证的用例,请始终检查<code>accessToken</code>是否可用,以及当请求中没有<code>accessToken</code>表示用户未经过身份验证时,您可以向用户发送<code>Account Link Card</code>。除了发送<code>Account Link card</code>的代码外,<strong>链接帐户过程中不涉及任何编码</p>
<p><strong>发送账户链接卡</strong>:</p>
<p>在您的回复中,JSON包含<code>LinkAccount</code>卡</p>
<pre><code>...
"outputSpeech": {
"type": "SSML",
"ssml": "<speak> Please link your account </speak>"
},
"card": {
"type": "LinkAccount"
}
...
</code></pre>