'错误403:指定项目的帐户已被停用'从java访问谷歌云存储API时

时间:2016-05-16 21:16:31

标签: google-cloud-messaging google-cloud-storage

创建了多个帐户,每次从cc收取1美元。然后我可以在https://console.cloud.google.com/中创建存储桶,之后我开始从我的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 个答案:

答案 0 :(得分:1)

错误403是您尝试列出不存在的项目的存储桶或您没有权限列出存储桶的错误响应的示例。

已禁用与拥有存储桶或对象的项目关联的帐户。查看Google Cloud Platform Console以查看结算是否存在问题,如果没有,请联系帐户支持。

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