php - `SignatureDoesNotMatch` 来自 Alexa Top Sites 服务的 AWS 的响应

标签 php amazon-web-services cryptography alexa-internet

我指的是Alexa Top Sites Developer Guide并使用their sample codes, both PHP and Ruby 。我收到以下 SignatureDoesNotMatch 错误:

<?xml version="1.0"?>
<Response><Errors><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
</Message></Error></Errors><RequestID>28c6b028-c4b6-66a2-f5d8-70d8dc21b8f8</RequestID>
</Response>

我使用同一用户尝试了两个不同的访问 key 并注册了 Alexa Web 信息服务,但没有成功。我在 Mac OS 10.9 和 10.10 上都尝试过这些脚本,我的时间设置设置为自动更新。

在 PHP 代码中,这是生成签名的部分:

/**
 * Generates a signature per RFC 2104
 *
 * @param String $queryParams query parameters to use in creating signature
 * @return String             signature
 */
protected function generateSignature($queryParams) {
    $sign = "GET\n" . strtolower(self::$ServiceHost) . "\n/\n". $queryParams;
    echo "String to sign: \n" . $sign . "\n\n";
    $sig = base64_encode(hash_hmac('sha256', $sign, $this->secretAccessKey, true));
    return rawurlencode($sig);
}

我不知道我做错了什么。

最佳答案

我明白了。 AWS 根用户可以发出请求,但我创建的 IAM 用户不能发出请求。我猜 root 用户可以访问 Alexa 服务,但不能访问 IAM 用户。

关于php - `SignatureDoesNotMatch` 来自 Alexa Top Sites 服务的 AWS 的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27238694/

相关文章:

python - python中的加密哈希和哈希表哈希有什么区别?

python - 在 .NET 中验证 Python Passlib 生成的 PBKDF2 SHA512 哈希

php - 如何在嵌入的 SoundCloud 播放器上添加搜索?

amazon-web-services - 使用具有严格白名单的公有子网与对 AWS 云资源使用私有(private)子网的缺点

node.js - 无法让 Node 服务器代理到 RedHat Ec2 实例上的 nginx

linux - 如何通过单个 IP 将流量从多个服务器路由到外部 API?

python pip密码学构建轮失败

php - 父类构造函数调用错误?

php - Yahoo Fantasy Sports API 未通过身份验证

PHP 数组到对象的转换