我想调用以下从云功能中描述的云SQL API。
- https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/export?hl = hl = en
我发现库打电话给GCP API。
- https://github.com/googleapis/google-cloud-node
- https://github.com/googleapis/google-cloud-go
但是,云SQL似乎没有任何模块。
我想知道为什么没有实施。API是相对较新的原因吗?还是我误解了库的目的,实际上它不应在库中实现?
在您链接的页面底部,您会以不同的语言找到示例代码,以通过构建客户端来调用该API。例如,Node.js
的示例代码看起来像:
const {google} = require('googleapis');
var sqlAdmin = google.sqladmin('v1beta4');
authorize(function(authClient) {
var request = {
// Project ID of the project that contains the instance to be exported.
project: 'my-project', // TODO: Update placeholder value.
// Cloud SQL instance ID. This does not include the project ID.
instance: 'my-instance', // TODO: Update placeholder value.
resource: {
// TODO: Add desired properties to the request body.
},
auth: authClient,
};
sqlAdmin.instances.export(request, function(err, response) {
if (err) {
console.error(err);
return;
}
// TODO: Change code below to process the `response` object:
console.log(JSON.stringify(response, null, 2));
});
});
function authorize(callback) {
google.auth.getApplicationDefault(function(err, authClient) {
if (err) {
console.error('authentication failed: ', err);
return;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
authClient = authClient.createScoped(scopes);
}
callback(authClient);
});
}
要连接到云功能的云SQL实例,请在此处遵循文档。
您可以使用gcloud SDK调用API。如果您只想导出数据库,请查看此文档:https://cloud.google.com/sdk/gcloud/reference/sql/sql/instances/export/export