【发布时间】:2018-02-07 13:25:06
【问题描述】:
我们可以使用任何 google API 来提供有关使用 Google Cloud Platform 所花费的总费用的信息吗?我尝试了一些 API(代码中显示了详细信息)。
API 1:
var google = require('googleapis');
var cloudbilling = google.cloudbilling('v1');
google.auth.getApplicationDefault(function(err, authClient) {
if (err) {
console.log('Authentication failed because of ', err);
return;
}
if (authClient.createScopedRequired &&
authClient.createScopedRequired()) {
var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
authClient = authClient.createScoped(scopes);
}
var request = {
name: "projects/<your-project-id>",
// Auth client
auth: authClient
};
cloudbilling.projects.getBillingInfo(request, function(err, result) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
});
我在 json 中得到的(关于计费信息)是:
data:
{ name: 'projects/<your-project-name>/billingInfo',
projectId: '<project-Id>',
billingAccountName: 'billingAccounts/<your-billing-id>',
billingEnabled: true }
}
现在我也尝试了其他 API,但它们也没有提供花费的总费用!。有什么办法可以找到账单吗?
【问题讨论】: