Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Node.js to call Google API and put it into a cloud function. client method cannot return data #1584

Closed
radianceltd opened this issue Jan 9, 2020 · 5 comments

Comments

@radianceltd
Copy link

radianceltd commented Jan 9, 2020

`exports.devicegetway = async (req,res) => {

const cloudRegion = 'us-central1';
const gatewayId = 'my-region-001';
const projectId = 'riltmw025tool-2019';
const registryId = 'my-registry-006s';

const client = getClient('riltmw025tool-2019-21396a54b9be.json');
listDevicesForGateway(client, projectId, cloudRegion, registryId, gatewayId);

}

const getClient = async (serviceAccountJson,res) => {
const authClient = await google.auth.getClient({
keyFilename: serviceAccountJson,
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
const discoveryUrl = 'https://cloudiot.googleapis.com/v1/projects/riltmw025tool-2019/locations/us-central1/registries/my-registry/devices';
google.options({
auth: authClient,
});
try {
return google.discoverAPI(discoveryUrl);
} catch (err) {
console.error('Error during API discovery.', err);
}
};

const listDevicesForGateway = async (client,projectId,cloudRegion,registryId,gatewayId) => {
const parentName = projects/${projectId}/locations/${cloudRegion}/registries/${registryId};
const request = {
parent: parentName,
'gatewayListOptions.associationsGatewayId': gatewayId,
};
let devices;
try {
const {data} = await client.projects.locations.registries.devices.list(
request
);
devices = data.devices;
} catch (err) {
console.error('Could not list devices', err);
return;
}
console.log('Current devices bound to gateway: ', gatewayId);
if (devices && devices.length > 0) {
devices.forEach(device => {
console.log(\tDevice: ${device.numId} : ${device.id});
});
} else {
console.log('No devices bound to this gateway.');
}
};
`
const {data} = await client.projects.locations.registries.devices.lis cannot return data

I try to use const client = new iot.v1.DeviceManagerClient to get only part of the API function data

IAM and service account / valid key are both stored in the project file, but this problem never returns to me

@radianceltd radianceltd changed the title 使用Node.js调用Google API并将其放入云函数中。client方法不能返回数据 Use Node.js to call Google API and put it into a cloud function. client method cannot return data Jan 9, 2020
@radianceltd
Copy link
Author

@radianceltd
Copy link
Author

@gguuss

@radianceltd
Copy link
Author

@fhinkel
Copy link
Contributor

fhinkel commented Jan 9, 2020

Hi @radianceltd, thank you for the detailed bug report. Unfortunately, this issue tracker has limited visibility and scope - basically, it's just for reporting issues with the samples contained here and is only watched by the folks who work on these samples.

We are happy to help you move this bug to venues where it'll get the attention of the appropriate product teams.

I'm going to close this issue because the folks who own this repo have no actionable way to resolve it directly, but please let us know if there's anything we can do to help!

@fhinkel fhinkel closed this as completed Jan 9, 2020
@radianceltd
Copy link
Author

@fhinkel Thank you for your reply, would you like to inquire whether Google has restricted Chinese computers from reading data through VPN nodes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants