0

so im using the youtube api to grab information about the live status of a channel. If you use this type of link normaly:https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=(CHANNELID)&eventType=live&type=video&key=(APIKEY)

you get no important information, but if the specified channel is live it gives alot of information like the status that it is indeed live. I am grabbing that information but it doesnt change, so i still get the return json like the channel isnt live but if i click the link i can clearly see all the information but it isnt grabbing it

client.on('message', async message => {
    
    
    
    if(message.content=="!cat"){
        let getData= async () =>{
            let response= await fetch("https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCvaTdHTWBGv3MKj3KVqJVCw&eventType=live&type=video&key=(APIKey")
            console.log(response)
            let Data=await response.json()
            console.log(Data)
            return Data
        }
        let FinalData= await getData()

        console.log(FinalData.liveBroadcastContent)
        message.reply(FinalData.liveBroadcastContent)
    
    }
}); 

this is what shows up in my fetch:

  kind: 'youtube#searchListResponse',
  etag: 'Byi7iAkYUIpWKxdVS-MPyYo1_sY',
  regionCode: 'DE',
  pageInfo: { totalResults: 1, resultsPerPage: 1 },
  items: [
    {
      kind: 'youtube#searchResult',
      etag: 'jTlF5DKseNmUsYji3o253M32ZhA',
      id: [Object],
      snippet: [Object]
    }
  ]
} 

this is what shows when i go onto the same link in my browser:

  "kind": "youtube#searchListResponse",
  "etag": "Byi7iAkYUIpWKxdVS-MPyYo1_sY",
  "regionCode": "DE",
  "pageInfo": {
    "totalResults": 1,
    "resultsPerPage": 1
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "jTlF5DKseNmUsYji3o253M32ZhA",
      "id": {
        "kind": "youtube#video",
        "videoId": "2DacDYB6jVs"
      },
      "snippet": {
        "publishedAt": "2021-11-29T06:00:03Z",
        "channelId": "UCvaTdHTWBGv3MKj3KVqJVCw",
        "title": "【シャイニングパール】地上へ戻ってきました#3【#スバおか対決 /ホロライブ】",
        "description": "_ 3つ目のバッチ目指してゴー!✨ スバルちゃん  :https://www.youtube.com/channel/UCvzGlP9oQwU--Y0r9id_jnA この放送は 株式会社ドワンゴ の実施するニコニコ ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/2DacDYB6jVs/default_live.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/2DacDYB6jVs/mqdefault_live.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/2DacDYB6jVs/hqdefault_live.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Okayu Ch. 猫又おかゆ",
        "liveBroadcastContent": "live",
        "publishTime": "2021-11-29T06:00:03Z"
      }
    }
  ]
}
eikor
  • 1
  • 2

1 Answers1

1

First of all I would suggest you remove the key from your code snippet, and make sure to make the key you've accidentally shared in here invalid from your google api admin panel.

However when I try to run your fetch, I get the expected result. I think you are victim to console.log not showing everything, see: console.log message is truncated

fresser
  • 41
  • 3
  • thank you for mentioning im resseting the key but if i try to console log only the part of the data i need it returns undefined which shouldnt be it should return "live" – eikor Nov 29 '21 at 18:44
  • Your console.log is not logging what you want at the moment. You are logging `liveBroadcastContent` as if it is in the root of the json, while you in this case might want to log `FinalData.items[0].snippet.liveBroadcastContent`. – fresser Nov 30 '21 at 08:24