Google cloud platform GCP云本机呼叫-设置项目预算-凭据问题

Google cloud platform GCP云本机呼叫-设置项目预算-凭据问题,google-cloud-platform,cloud,google-cloud-billing,Google Cloud Platform,Cloud,Google Cloud Billing,试图使用下面的代码设置项目预算,但它总是给出凭据错误 计费帐户名称:0146F3-46CC06-71C2DA项目\u id:firebase Breezool io.grpc.StatusRuntimeException:UNAUTHENTICATED:Failed computing credential metadata' 我的代码是 AppIdentityService appIdentityService = AppIdentityServiceFactory.g

试图使用下面的代码设置项目预算,但它总是给出凭据错误

计费帐户名称:0146F3-46CC06-71C2DA项目\u id:firebase Breezool io.grpc.StatusRuntimeException:UNAUTHENTICATED:Failed computing credential metadata'

我的代码是

            AppIdentityService appIdentityService = AppIdentityServiceFactory.getAppIdentityService();

            appIdentityService
            .getAccessToken(Collections.singletonList("https://www.googleapis.com/auth/cloud-billing"))
            .getAccessToken();

            Credentials credentials =
                AppEngineCredentials.newBuilder()
                    .setScopes(Collections.singletonList("https://www.googleapis.com/auth/cloud-billing"))
                    .setAppIdentityService(appIdentityService)
                    .build();               


            // LocalDate expiry_date = LocalDate.now().plusDays(1); 
            // java.util.Date expiry_date1 = java.util.Date.from(expiry_date.atStartOfDay(ZoneId.systemDefault()).toInstant());
            // Credentials credential = OAuth2Credentials.create(new AccessToken(google_credential.getAccessToken(),expiry_date1));

            BudgetServiceSettings budgetServiceSettings =
            BudgetServiceSettings.newBuilder()
                .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
                .build();
            BudgetServiceClient budgetServiceClient = BudgetServiceClient.create(budgetServiceSettings);
            
            BillingAccountName parent = BillingAccountName
            .newBuilder()
            .setBillingAccount(billingAccount)
            .build();

            Budget budget = Budget
            .newBuilder()
            .setDisplayName(budgetName)
            .setBudgetFilter(Filter.newBuilder()
                        .addProjects("projects/"+project_id)
                        // .setProjects(1, "projects/"+project_id)
                        .setCreditTypesTreatment(Filter.CreditTypesTreatment.INCLUDE_ALL_CREDITS)
                        // .setSubaccounts(0, "billingAccounts/"+client_billingAccount) 
                        .build())
            .setAmount(BudgetAmount.newBuilder()
                        .setSpecifiedAmount(Money.newBuilder().setCurrencyCode("USD").setUnits(Long.parseLong(budget_amount)).build())
                        .build())
            .addThresholdRules(ThresholdRule.newBuilder().setSpendBasis(Basis.CURRENT_SPEND).setThresholdPercent(0.9).build())
            .addThresholdRules(ThresholdRule.newBuilder().setSpendBasis(Basis.CURRENT_SPEND).setThresholdPercent(1.0).build())
            .build();


            budgetServiceClient.createBudget(parent, budget);
            // System.out.println("Successful setBudget");
            logger.info("Successful setBudget");

            status =  true;

用详细信息编辑您的问题。你在哪里运行这个代码?您如何设置授权(服务帐户以及如何指定)?将发布的代码简化为一个完整的示例,以再现问题(可能只是最上面的部分)。包括库导入、生成文件等。最有可能的情况是,您设置的ADC(应用程序默认凭据)不正确,或者在具有错误作用域的计算服务上运行。