在下面,我在 application.properties 中设置变量并尝试使用默认服务实例:
private static void testListGCPBucket() String configPath) throws IOException {
Storage storage = StorageOptions.getDefaultInstance().getService();
System.out.println("Buckets:");
Page<Bucket> buckets = storage.list();
for (Bucket bucket : buckets.iterateAll()) {
System.out.println(bucket.toString());
}
System.out.println("completed...");
}
application.config文件内容:
GOOGLE_APPLICATION_CREDENTIALS =classpath:config.json
但这不起作用我收到以下错误:
Caused by: com.google.api.client.http.HttpResponseException: 403 Forbidden
POST https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/proj-workload-id-svc-acct@idmp-mii-dev-ddb5.iam.gserviceaccount.com:generateAccessToken
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1116)
at com.google.auth.oauth2.ImpersonatedCredentials.refreshAccessToken(ImpersonatedCredentials.java:441)
... 36 more