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

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

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

相关标签:
14条回答
  • 2020-11-27 07:19
    http://www.youtube.com/watch?v=bQVoAWSP7k4  
    http://www.youtube.com/watch?v=bQVoAWSP7k4&feature=popular  
    http://www.youtube.com/watch?v=McNqjYiFmyQ&feature=related&bhablah  
    http://youtube.com/watch?v=bQVoAWSP7k4
    var matches = $('#videoUrl').val().match(/http:\/\/(?:www\.)?youtube.*watch\?v=([a-zA-Z0-9\-_]+)/);
    if (matches) {
        alert('valid');
    } else {
        alert('Invalid');
    }
    
    0 讨论(0)
  • 2020-11-27 07:24

    You should request to this URL

    https://www.googleapis.com/youtube/v3/videos?id={the_id_of_the_video}&key={your_api_key}&part=status
    

    After that, you will receive the response json that contains uploadStatus field

    {
        etag = "\"I_8xdZu766_FSaexEaDXTIfEWc0/8QgL7Pcv5G8OwpNyKYJa8PaQTc0\"";
        items =     (
                    {
                ...
                status =             {
                    embeddable = 1;
                    license = youtube;
                    privacyStatus = public;
                    publicStatsViewable = 1;
                    uploadStatus = processed;
                };
            }
        );
        ...
    }
    

    And there are 5 possible value for uploadStatus

    deleted, failed, processed, rejected, uploaded

    For uploadStatus = processed or uploaded => your youtube video is available

    0 讨论(0)
提交回复
热议问题