Youtube API v3, Invalid parameter issue while video play

1.9k Views Asked by At

I am using youtube API to show video list and play that video. All was working fine with v2 but as now it's deprecated I have updated it with v3.

I am getting youtube play list successfully but when I play with that videoId provided in API it fails and showing me error as below.

Also it plays fine in browser safari as well as in mozila.

Video URL VideoLink

    **Error**
    Error Domain=YouTubeVideoErrorDomain Code=2 "Invalid parameters." UserInfo=0x7f877064c610 
    {NSURL=https://www.youtube.com/get_video_info?el=detailpage&hl=en&ps=default&video_id=https%3A%2F%2F
    www.youtube.com%2Fwatch%3Fv%3DRgKAFK5djSk%26feature%3Dyoutube_gdata, NSLocalizedDescription=Invalid parameters.}
1

There are 1 best solutions below

2
On

My understanding of your question is that you are struggling to get the video to play in your app? And from your error output, to me anyway, it seems like you are trying to pass the URL to something native like MPMoviePlayerController?

If so, this can be done, but the way you are approaching it is wrong. What you need to do is to use a YouTube Video URL link extractor library which will use the Video ID you get back from the YouTube API V3 to then get a list of MP4 video URL's. You can then use these URL's to play the video natively.

Here is a great link extractor library that you can use: https://github.com/runmad/RMYouTubeExtractor

I should mention that this is against the YouTube ToS, so if you want to do it the way that Google permits, then you need to simply embed that video in a small UIWebView. (Which looks and works horribly). Use this library to do just that: https://github.com/youtube/youtube-ios-player-helper