0
<?php
$url="https://www.googleapis.com/storage/v1/b/sts_bucket/o?key=xxx&project=xxxxx
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($ch);
if ($json_response == FALSE){
echo "cURL error: " . curl_error($ch);
}
curl_close($ch);
echo "</pre>";
echo $json_response;
echo "</pre>";
?>
我是makin下面的请求谷歌云存储获取桶信息。但它显示以下错误: -谷歌云存储桶内容
{ "error": { "errors": [ { "domain": "global", "reason": "required",
"message": "Anonymous users does not have storage.objects.list access to
bucket sts_bucket.", "locationType": "header", "location": "Authorization"
} ], "code": 401, "message": "Anonymous users does not have
storage.objects.list access to bucket sts_bucket." } }
但我怎么能在我的上面的代码中生成它? –
我建议不要尝试手动编码基于OAuth2的身份验证,因为执行操作所需的访问令牌在有限的时间内有效,并且您需要在令牌到期时获取新的令牌(请参阅https://cloud.google。 COM /文档/认证/工具入门)。相反,使用为您处理OAuth2的库更容易。我没有使用PHP OAuth2库的经验,但您可能会从以下某个库中找到可用的库:https://www.google.com/search?q=php+oauth2 –