0

I'm trying to use Youtube API for my project. Here is my problem.

I have a array of video titles and trying to put them in to my playlist. I created a new playlist and got a playlist id, I got video_id from video title using search api. I used for loop to put videos to my playlist. Some of them are working, but some of them are getting 500 error.

I checked the error and checked that the I got video ID right, and when I tried individually with the same request, it worked.

I tried several method like giving delay to the api request, axios interceptors etc

  "error": {
    "code": 500,
    "message": "Internal error encountered.",
    "errors": [
      {
        "message": "Internal error encountered.",
        "domain": "global",
        "reason": "backendError"
      }
    ],
    "status": "INTERNAL"
  }
}

Here is the for loop.(logic: get videoId from videoList(It's a array of video titles)=> put it in my playlist)

    for (let i = 0; i < videoList.length; i++) {
      params.q = checkValue[i];
      await searchVideo(params).then((res) => {
        try {
          addToPlayList(playlistId, res.items[0].id.videoId);
        } catch (error) {
          console.log(error);
        }
      });
    }

Here is my axios code

 baseInstance
      .post(
        `https://www.googleapis.com/youtube/v3/playlistItems?&part=snippet&resource.snippet.playlistId=${playlistId}&resource.snippet.resourceId.videoId=${vid}&resource.snippet.resourceId.kind=youtube%23video`
      )

Any idea what can be the problem?

  • When running again your code with a video id that first returned an a error, are you able to get it accepted the second time? Otherwise maybe [this solution](https://stackoverflow.com/a/71970181/7123660) may interest you. – Benjamin Loison Oct 06 '22 at 07:43
  • Where are you adding the post body? This method only has a single parm that should be sent in the query string, everything else should be in the body. [playlistitens.insert](https://developers.google.com/youtube/v3/docs/playlistItems/insert?apix=true) – Linda Lawton - DaImTo Oct 06 '22 at 09:49
  • @BenjaminLoison Thanks for the quick reply. Yes, when it's run on for-loop some of them gets an error. (only about 13 out of 20 made it)And if I extract those video_id who caught an error and send it individually then it works. My curiosity is that if my code is wrong then all of my attempts should get an error. But why only some of them are getting an error?:( – ChagHeon Yoo Oct 06 '22 at 11:44
  • @DaImTo I didn't think about that part. I didn't know how to handle an nested object in a body. So I just put the whole thing in the url. But I just figured it out and when my quota is reset I'll try it and let you know if there's any difference! – ChagHeon Yoo Oct 06 '22 at 11:48
  • @DaImTo I changed my code but still getting same result.. – ChagHeon Yoo Oct 07 '22 at 08:35

0 Answers0