1
訪問谷歌雲存儲API創建了多個帳戶,每次從cc收取1美元,然後我可以在https://console.cloud.google.com/中創建存儲桶,之後我從我的java代碼開始訪問存儲桶,然後帳戶被阻止,我嘗試了多次。'錯誤403:指定項目的帳戶已被禁用',同時從java
Java代碼:
創建憑證
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
List<String> scopes = new ArrayList<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
Credential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(
propsReaderUtil.getValue(ACCOUNT_ID_PROPERTY))
.setServiceAccountPrivateKeyFromP12File(
new File(getClass().getClassLoader().getResource(propsReaderUtil.getValue(
PRIVATE_KEY_PATH_PROPERTY)).getFile()))
.setServiceAccountScopes(scopes).build();
storage = new Storage.Builder(httpTransport, jsonFactory,
credential).setApplicationName(
propsReaderUtil.getValue(APPLICATION_NAME_PROPERTY))
.build();
載流 寄存存儲= getStorage();
StorageObject object = new StorageObject();
object.setBucket(bucketName);
InputStream stream = file.getInputStream();
try {
String contentType = URLConnection
.guessContentTypeFromStream(stream);
InputStreamContent content = new InputStreamContent(contentType,
stream);
Storage.Objects.Insert insert = storage.objects().insert(
bucketName, null, content);
insert.setName(file.getName());
insert.execute();
} finally {
stream.close();
}
請讓我知道如果我做錯了什麼,或建議我最好的方式來做到這一點。 任何建議表示讚賞... 在此先感謝...