public static object DeleteDevice(string projectId, string cloudRegion, string registryId, string deviceId)
{
var cloudIot = CreateAuthorizedClient();
// The resource name of the location associated with the key rings.
var name = $"projects/{projectId}/locations/{cloudRegion}/registries/{registryId}/devices/{deviceId}";
try
{
var res = cloudIot.Projects.Locations.Registries.Devices.Delete(name).Execute();
Console.WriteLine($"Removed device: {deviceId}");
}
catch (Google.GoogleApiException e)
{
Console.WriteLine(e.Message);
if (e.Error != null) return e.Error.Code;
return -1;
}
return 0;
}
# project_id = "Your Google Cloud project ID"
# location_id = "The Cloud region the registry is located in"
# registry_id = "The registry to create a device in"
# device_id = "The identifier of the device to delete"
require "google/apis/cloudiot_v1"
# Initialize the client and authenticate with the specified scope
Cloudiot = Google::Apis::CloudiotV1
iot_client = Cloudiot::CloudIotService.new
iot_client.authorization = Google::Auth.get_application_default(
"https://www.googleapis.com/auth/cloud-platform"
)
# The resource name of the location associated with the project
parent = "projects/#{project_id}/locations/#{location_id}"
device_path = "#{parent}/registries/#{registry_id}/devices/#{device_id}"
# Delete the device
result = iot_client.delete_project_location_registry_device(
device_path
)
puts "Deleted device."