【发布时间】:2020-04-10 14:39:41
【问题描述】:
我已经尝试了下面的代码,它工作正常。但是,如果我可以仅使用 OAuth 2.0 访问令牌和存储桶名称来获取签名 URL,那将是理想的。
我尝试了很多东西,但仍然无处可去。
function getSignedURL($file, $expiryMinutes = 30)
{
$privateKeyFileContent = '{
// service account generated key
}';
$storage = new StorageClient([
'keyFile' => json_decode($privateKeyFileContent, true)
]);
$bucket = $storage->bucket("as-portal");
$object = $bucket->object($file);
$url = $object->signedUrl(
# This URL is valid for 15 minutes
new \DateTime("$expiryMinutes min"),
[
'version' => 'v4',
]
);
}
任何帮助将不胜感激!
【问题讨论】:
标签: php oauth-2.0 google-cloud-storage access-token