YouTube

ÜCRETSİZ PREMIUM
Taraf Dataverse | Güncelleyen 7 days ago | Data
Popülerlik

9.6 / 10

Gecikme

136ms

Hizmet Düzeyi

100%

Health Check

100%

Tüm Eğitimlere Dön (7)

How to Get Video Title and Views using TypeScript and YouTube Data API

This tutorial shows how to retrieve the title and view count of a YouTube video using the YouTube Data API.

Steps

  1. Make a request to the YouTube Data API endpoint:

    const response = await fetch(url, {
      url: '${API_HOST}/videos',
      params: {
        part: 'snippet,contentDetails,statistics', 
        id: 'Ks-_Mh1QhMc'
      },
      headers: { 'X-RapidAPI-Key': RAPID_API_KEY }
    });
    
    • Set the url to the videos endpoint
    • Specify the part parameter to include snippet, content details, and statistics
    • Provide the video id
    • Include your RapidAPI key in the headers
  2. Parse the JSON response:

    const result = await response.json();
    
  3. Extract the video title and view count from the response:

    const title = result.items[0].snippet.title;
    const views = result.items[0].statistics.viewCount;
    

    The video title is located under items[0].snippet.title and the view count under items[0].statistics.viewCount in the response object.

That’s it! You have now retrieved the title and view count for the specified YouTube video using a simple API request in JavaScript.