How do I check if a video exists on YouTube, using PHP?

后端 未结 14 1621
[愿得一人]
[愿得一人] 2020-11-27 06:40

How do I check if a video exists on YouTube, using PHP?

14条回答
  •  独厮守ぢ
    2020-11-27 07:18

    Here is the solution that I use to check if YouTube video exists using video id. This is C# code, but basically you can check if the thumbnail of the video exists, you will either get 200 or 404 which is very convenient.

        private async Task VideoExists(string id)
        {
            var httpClient = new HttpClient();
            var video = await httpClient.GetAsync($"https://img.youtube.com/vi/{id}/0.jpg");
            return video.IsSuccessStatusCode;
        }
    

提交回复
热议问题