我有一个使用骆驼从对象存储(谷歌云平台)获取数据的弹簧启动应用程序。
这是我在eclipse中的代码:
package footballRestAPIs;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
import core.ErrorProcessor;
@Component
public class ListObjFromGCP extends RouteBuilder{
@Override
public void configure() throws Exception {
onException(Exception.class).handled(true)
.process(new ErrorProcessor());
rest("/").produces("application.json")
.get("selectPhoto")
.to("direct:selectPhoto");
from("direct:selectPhoto")
.to("google-storage://sagessapp_test?operation=listObjects")
.log("${body}");
}
}
这是 application.properties 文件,其中服务帐户密钥的路径是:
spring.cloud.gcp.credentials.location=/Users/User/Downloads/gcp-credentials.json
当我运行 spring boot 应用程序时,出现以下错误:
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
GET https://storage.googleapis.com/storage/v1/b/sagessapp_test?projection=full
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Anonymous caller does not have storage.buckets.get access to the Google Cloud Storage bucket.",
"reason" : "required"
} ],
"message" : "Anonymous caller does not have storage.buckets.get access to the Google Cloud Storage bucket."
}
是否有可能有另一种方法来提供服务帐户密钥的路径,或者存在其他问题。谢谢!