0
GCS 및 해당 Java API를 시작하기 만하면됩니다. Google Plus example을 수정했으며 버킷을 검색하려고합니다.GCS : 400 잘못된 요청 버킷 검색
나는 오류를 얻을 :
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
}
여기 내 관련 코드입니다 :
홈페이지 :
public static void main(String[] args)
{
try
{
try
{
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
// service account credential (uncomment setServiceAccountUser for domain-wide delegation)
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(StorageScopes.DEVSTORAGE_READ_WRITE)
.setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_NAME))
// .setServiceAccountUser("[email protected]")
.build();
// set up global Storage instance
storage = new Storage.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
// run commands
getBucket();
// success!
return;
} catch (IOException e)
{
System.err.println(e.getMessage());
}
} catch (Throwable t)
{
t.printStackTrace();
}
System.exit(1);
}
가져 버킷 방법 :
/** Get a BUCKET??? for which we already know the ID. */
private static void getBucket() throws IOException
{
View.header1("Retrieve a bucket by name.");
String bucketName = "gs://gsdogs";
Bucket bucket = storage.buckets().get(bucketName).execute();
View.show(bucket);
}
상수 :
은private static final String CLIENT_ID = "************.apps.googleusercontent.com";
private static final String KEY_FILE_NAME = "privatekey.p12";
private static final String APPLICATION_NAME = "Elf-MobileCCtv/1.0";
/** E-mail address of the service account. */
private static final String SERVICE_ACCOUNT_EMAIL = "************@developer.gserviceaccount.com";
/** Global instance of the HTTP transport. */
private static HttpTransport HTTP_TRANSPORT;
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
// We are using GCS not Google plus.
private static Storage storage;
미리 감사드립니다.