Groovy/Java Google存储验证和请求
Groovy/Java是否有任何简单的代码示例可以进行身份验证并向Google Storage发出请求。我想使用此API将对象从一个bucket复制到另一个bucket: 以下是我尝试过的:Groovy/Java Google存储验证和请求,java,rest,groovy,google-cloud-storage,Java,Rest,Groovy,Google Cloud Storage,Groovy/Java是否有任何简单的代码示例可以进行身份验证并向Google Storage发出请求。我想使用此API将对象从一个bucket复制到另一个bucket: 以下是我尝试过的: String sourceStorageID = "XXX" String destinationStorageID = "YYY" String sourceFileName = "fileXXX" String destinationFileName = "fileYYY" //h
String sourceStorageID = "XXX"
String destinationStorageID = "YYY"
String sourceFileName = "fileXXX"
String destinationFileName = "fileYYY"
//https://www.googleapis.com/storage/v1/b/sourceBucket/o/sourceObject/copyTo/b/destinationBucket/o/destinationObject
String urlToCopyFile = "https://www.googleapis.com/storage/v1/b/" + sourceStorageID + "/o/" + sourceFileName + "/copyTo/b/" + destinationStorageID + "/o/" + destinationFileName
RestBuilder rest = new RestBuilder()
def exportFinishedJSON = rest.get(objectsListURL) {}?.json
我得到的回应是:
{"error":{"message":"Anonymous users does not have storage.objects.list access to bucket XXX.","errors":[{"message":"Anonymous users does not have storage.objects.list access to bucket XXX","location":"Authorization","reason":"required","locationType":"header","domain":"global"}],"code":401}}
我知道我需要先进行身份验证,但如何进行?我阅读了大量的文档,但没有任何简单的Java实现示例。它真的是杂乱无章,信息太多了,我已经厌倦了阅读和搜索
我还使用ApiKey搜索了解决方案,在文档中,它说只需将其作为参数附加到URL,我尝试如下:
String urlToCopyFile = "https://www.googleapis.com/storage/v1/b/" + sourceStorageID + "/o/" + sourceFileName + "/copyTo/b/" + destinationStorageID + "/o/" + destinationFileName + "&key=" + myApiKey
但是没有成功
对于我的问题,有什么简单的解决方法吗
提前谢谢
编辑:还尝试了以下不同方法:
if (storageObject == null) {instance.authenticate();}
StorageObject newObject = new StorageObject()
newObject.setName(destinationObjectName)
Storage.Objects.Copy request = storageObject.objects().copy(sourceStorageID, sourceObjectName, destinationStorageID, destinationObjectName, newObject);
request.execute();
现在得到这个错误:
GoogleJsonResponseException occurred when processing request: [GET] /concierge/test/index
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Required",
"reason" : "required"
} ],
"message" : "Required"
}. Stacktrace follows:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Required",
"reason" : "required"
} ],
"message" : "Required"
}
在groovy中,如果您使用它不是我问题的解决方案,那么它将很容易…在groovy中,如果您使用它不是我问题的解决方案,那么它将很容易。。。