2016-05-16 32 views
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(); 
    } 

請讓我知道如果我做錯了什麼,或建議我最好的方式來做到這一點。 任何建議表示讚賞... 在此先感謝...

回答

1

錯誤403是您收到錯誤響應的示例,如果您嘗試列出不存在項目的存儲桶或不存在的項目的存儲桶有權列出桶。

與擁有存儲桶或對象的項目關聯的帳戶已被禁用。檢查Google Cloud Platform Console以查看帳單是否存在問題,如果不存在,請聯繫帳戶支持。

更多信息可在HTTP Status and Error Codes中找到。