Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在亚马逊登录时,用户表示尚未同意,但他们已经同意了——Alexa SMAPI_Javascript_Php_Curl_Alexa Skills Kit_Alexa Skill - Fatal编程技术网

Javascript 在亚马逊登录时,用户表示尚未同意,但他们已经同意了——Alexa SMAPI

Javascript 在亚马逊登录时,用户表示尚未同意,但他们已经同意了——Alexa SMAPI,javascript,php,curl,alexa-skills-kit,alexa-skill,Javascript,Php,Curl,Alexa Skills Kit,Alexa Skill,我正在尝试使用技能管理API(SMAPI)检索Alexa开发者帐户上的技能列表 我有以下HTML/javascript: <BODY> <a href id="LoginWithAmazon"> <img border="0" alt="Login with Amazon" src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gry_312x64.png" w

我正在尝试使用技能管理API(SMAPI)检索Alexa开发者帐户上的技能列表

我有以下HTML/javascript:

<BODY>
    <a href id="LoginWithAmazon">
        <img border="0" alt="Login with Amazon" src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gry_312x64.png" width="156" height="32" />
    </a>
    <div id="amazon-root"></div>
    <script type="text/javascript">
        var client_id = "<client id>";
        window.onAmazonLoginReady = function() {
          amazon.Login.setClientId(client_id);
        };
        (function(d) {
          var a = d.createElement('script'); a.type = 'text/javascript';
          a.async = true; a.id = 'amazon-login-sdk';
          a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
          d.getElementById('amazon-root').appendChild(a);
        })(document);

        document.getElementById('LoginWithAmazon').onclick = function() {
            options = {
                scope : 'profile postal_code alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test',
                interactive: 'always',
                response_type: 'code'
            };
            amazon.Login.authorize(options, '<login page url>');
            return false;
        };
    </script>
</BODY>
我收到用户未同意此操作


我一定错过了一些基本的东西。我的印象是,最初请求中的范围:
profile邮政编码alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test
足以提供访问权限。我已确认Amazon帐户显示应用程序具有访问上述权限的权限。

我还尝试了其他端点,结果相同,我尝试将内容类型更改为application/json,这会导致“无效/过期令牌”错误。我还尝试添加文档中列出的所有范围(尽管有些显然是多余的)我也尝试删除权限并重新添加它们。读取成功,但错误依然存在。我已确认这是LWA的问题。亚马逊正在解决此问题。目前,您可以通过删除配置文件和邮政编码请求并分别请求来解决此问题。
$grant_type = 'authorization_code';
$client_id = $GLOBALS['client_id']; //your client id
$client_secret = $GLOBALS['client_secret']; //your client secret

$data = array(
    "grant_type"=>"authorization_code",
    "code" => $code,
    "client_id"=> $client_id,
    "client_secret"=> $client_secret
);
$postvars = '';
foreach($data as $key=>$value) {
    $postvars .= $key . "=" . $value . "&";
}
$ch = curl_init('https://api.amazon.com/auth/o2/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8'));
$result = curl_exec($ch);
curl_close($ch);
$result_arr = json_decode($result, true);
if (isset($result_arr['error']) == true){ //there was an error obtaining the auth token 
    var_dump($result);
    die('Error: There was an error authenticating with Amazon. Can you please start over again? Click <a href="index.php">here</a> to start again.');
}
return $result_arr;
// exchange the access token for list of skills
$c = curl_init('https://api.amazonalexa.com/v0/skills/');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Authorization: ' . $access_token));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_POST, 1);

$r = curl_exec($c);
curl_close($c);
var_dump($r);