October 4, 2015

Get Category of Video by Video ID

public Category GetCategoryOfVideo(string VideoID)
        {
            RestRequest request = new RestRequest(Method.GET)
            {
                Resource = "youtube/v3/videos?id=" + VideoID + "&key="+API_KEY + "&part=snippet,recordingDetails",
                RequestFormat = DataFormat.Json
            };

            var response = _client.Execute(request) as RestResponse;

            JObject joResponse = JObject.Parse(response.Content.ToString());
            string CategoryID = (string)joResponse["items"][0]["snippet"]["categoryId"];

            Category result = GetVideoCategories().Find(x => x.ID == CategoryID);

            return result;
        }

    public class Category
    {
        private string CategoryID;
        private string CategoryTitle;

        public Category(string _ID, string _Title)
        {
            CategoryID = _ID;
            CategoryTitle = _Title;
        }

        public string ID
        {
            get { return CategoryID; }
            set { CategoryID = value; }
        }

        public string Title
        {
            get { return CategoryTitle; }
            set { CategoryTitle = value; }
        }
    }


Just pass Video ID in above method you will get Category details of video.

No comments:

Post a Comment