Get channel (v1)

Retrieve the details of an existing channel.

Code sample

Node.js

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Node.js API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

'use strict';

const {LivestreamServiceClient} = require('@google-cloud/livestream');
const {status} = require('@grpc/grpc-js');

const client = new LivestreamServiceClient();

/**
 * Retrieves details of a specific channel.
 *
 * @param {string} projectId - The Google Cloud project ID (for example, 'example-project-id')
 * @param {string} locationId - The Google Cloud region where the service is located (for example, 'us-central1')
 * @param {string} channelId - The user-defined identifier of the channel to retrieve (for example, 'example-channel-id')
 */
async function getChannel(projectId, locationId, channelId) {
  try {
    const name = `projects/${projectId}/locations/${locationId}/channels/${channelId}`;

    const [channel] = await client.getChannel({name});

    console.log(`Channel name: ${channel.name}`);
    console.log(`Channel state: ${channel.state}`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Channel not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied: ${err.message}`);
    } else {
      console.error(`API error: ${err.message}`);
    }
  }
}

module.exports = { getChannel };

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.