【发布时间】:2013-12-21 01:09:49
【问题描述】:
我可以使用 google-api-php-client 将文件 (image.png) 放到我的 Google Cloud Storage 存储桶中,但现在我无法尝试创建签名的 url 以从我的网站。示例代码:
$bucketName = 'bucket-name';
$id = 'image.png';
$serviceAccountName = '123456789-xxxx@developer.gserviceaccount.com';
$privateKey = file_get_contents($location_to_key_file);
$signer = new \Google_P12Signer($privateKey, "notasecret");
$ttl = time() + 3600;
$stringToSign = "GET\n" . "\n" . "\n" . $ttl . "\n". '/' . $bucketName . '/' . $id;
$signature = $signer->sign(utf8_encode($stringToSign));
$finalSignature = \Google_Utils::urlSafeB64Encode($signature);
$host = "https://".$bucketName.".storage.googleapis.com";
echo $host. "/".$id."?GoogleAccessId=" . $serviceAccountName . "&Expires=" . $ttl . "&Signature=" . $finalSignature;
返回:
<Error><Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message>
<StringToSign>
GET 1387590477 /bucketname/image.png</StringToSign></Error>
我使用 google-api-php-client 和 php 5.5
我举了几个例子:
https://groups.google.com/forum/#!topic/gs-discussion/EjPRAWbWKbw
https://groups.google.com/forum/#!msg/google-api-php-client/jaRYDWdpteQ/xbNTLfDhUggJ
也许配置值没有正确传递? 我认为应该使用服务帐户电子邮件。还尝试在 $stringToSign 中包含 md5hash 和 content-type,结果相同。
任何帮助/提示将不胜感激。
【问题讨论】:
标签: php google-api google-cloud-storage