更新
あなたが明示的に探索ドキュメントからAPIをロードしないと、現在、NodeJSクライアントライブラリがのIoTとの問題を抱えていること。表示されます
const serviceAccountJson = `/home/class/iot_creds.json`;
const API_VERSION = 'v1';
const DISCOVERY_API = 'https://cloudiot.googleapis.com/$discovery/rest';
function getClient (serviceAccountJson, cb) {
const serviceAccount = JSON.parse(fs.readFileSync(serviceAccountJson));
const jwtAccess = new google.auth.JWT();
jwtAccess.fromJSON(serviceAccount);
// Note that if you require additional scopes, they should be specified as a
// string, separated by spaces.
jwtAccess.scopes = 'https://www.googleapis.com/auth/cloud-platform';
// Set the default authentication to the above JWT access.
google.options({ auth: jwtAccess });
const discoveryUrl = `${DISCOVERY_API}?version=${API_VERSION}`;
google.discoverAPI(discoveryUrl, {}, (err, client) => {
if (err) {
console.log('Error during API discovery', err);
return undefined;
}
cb(client);
});
}
オリジナル
NodeJS management sampleは、現在のGoogle APIクライアントを使用しています(例えば"googleapis": "20.1.0"
でpackage.json:
は、あなたのAPIクライアントを初期化するために、次の操作を行い、今のところ、この問題を回避するために、)ライブラリであり、別個のライブラリではありません。
あなたがまだの場合は、サンプルのreadmeで説明したようにローカルでサンプルを実行してみてください:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
cd nodejs-docs-samples/iot/manager
npm install
node manager.js
サンプルは、ローカルに動作しない場合は、私たちはノードのバージョン(node --version
)を教えてくださいとインストールされているモジュールのバージョン(のpackage.lockまたはnpm ls
の出力)。
サンプルがローカルで(npm install
の実行後に)動作する場合、問題はクラウド機能のバックエンドからサンプルがどのように実行されているかにあります。