我尝试从云功能发送命令,我收到错误:服务当前不可用。
Package.JSON“依赖项”:{“firebase-admin”:“~6.0.0”,“firebase-functions”:“^2.0.3”,“googleapis”:“34.0.0”}
const parentName = `projects/${projectId}/locations/${cloudRegion}`;
const registryName = `${parentName}/registries/${reqData.registryId}`;
const binaryData = Buffer.from(JSON.stringify(reqData.message)).toString('base64');
const request = {
name: `${registryName}/devices/${reqData.deviceId}`,
binaryData: binaryData
};
google.auth.getClient().then((authClient) => {
const discoveryUrl =
`${DISCOVERY_API}?version=${API_VERSION}`;
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
// Scopes can be specified either as an array or as a single,
// space-delimited string.
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform'
]);
}
google.options({
auth: authClient
});
google.discoverAPI(discoveryUrl).then((client, err) => {
if (err) {
console.log('Error during API discovery', err);
return undefined;
}
client.projects.locations.registries.devices.sendCommandToDevice(request,
(err, data) => {
if (err) {
console.log('Could not send command:', request);
console.log('Message: ', err);
} else {
console.log('Success :', data.statusText);
}
});
});
});
日志:{ 错误:该服务当前不可用。在 createError (/user_code/node_modules/googleapis/node_modules/axios/lib/core/createError.js:16:15) 在结算 (/user_code/node_modules/googleapis/node_modules/axios/lib/core/settle.js:18: 12) 在 Unzip.emit (events.js: 185:7) 在 endReadableNT (_stream_readable.js:974:12) 在 _combinedTickCallback (internal/process/next_tick.js:80:11) 在 process._tickDomainCallback (internal/process/next_tick.js:128:9)