public IActionResult Index(string search = "", string token = "")
        {
            if (!string.IsNullOrEmpty(_apiKey))
            {
                string        path     = $"https://www.googleapis.com/youtube/v3/search?part=snippet&pageToken={token}&maxResults=12&q={search}&regionCode=pl&relevanceLanguage=pl&type=video&key={_apiKey}";
                YouTubeSearch ytsearch = APIRequest(path).ToObject <YouTubeSearch>();

                ViewBag.Search = search;

                return(View(ytsearch));
            }
            else
            {
                return(View("NoKey"));
            }
        }
Beispiel #2
0
        public Test_YouTubeSearch()
        {
            var items = YouTubeSearch.Query("Test", 1);

            int i = 1;

            foreach (var item in items)
            {
                Console.WriteLine("Item: " + i);
                Console.WriteLine("Author: " + item.getAuthor());
                Console.WriteLine("Description: " + item.getDescription());
                Console.WriteLine("Duration: " + item.getDuration());
                Console.WriteLine("Thumbnail: " + item.getThumbnail());
                Console.WriteLine("Title: " + item.getTitle());
                Console.WriteLine("Url: " + item.getUrl());
                Console.WriteLine(Environment.NewLine);

                i++;
            }
        }
        public ActionResult YouTubeSearch(string query)
        {
            var apiKey = System.Web.HttpContext.Current.Application["GoogleAPIKey"].ToString();

            GoogleAdapter.ApiKey = apiKey;

            var model = new YouTubeSearch()
            {
                Query = query, ResultsXml = string.Empty
            };

            if (string.IsNullOrEmpty(query))
            {
                return(this.View(model));
            }

            model.ResultsXml = GoogleAdapter.SearchYouTube(query);

            return(this.View(model));
        }
Beispiel #4
0
        // GET: Giphy
        public ActionResult Index()
        {
            //create request to the api
            string     apikey  = "AIzaSyBqSlrPVyq43u8Vo0vi4GJG8k9dvPzS-Gg";
            WebRequest request = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&q=pokemon&key=" + apikey);

            //send the request off
            WebResponse response = request.GetResponse();

            //get back the response stream
            System.IO.Stream stream = response.GetResponseStream();
            //Make It Accessible
            StreamReader reader = new StreamReader(stream);
            //put into string which is json formatted
            string        responseFromServer = reader.ReadToEnd();
            JObject       parsedString       = JObject.Parse(responseFromServer);
            YouTubeSearch search             = parsedString.ToObject <YouTubeSearch>();

            return(View());
        }
Beispiel #5
0
 public AppHub(IDistributedCache cache, ApplicationDbContext context)
 {
     _cache    = cache;
     dbHandler = new DBHandler(context);
     search    = new YouTubeSearch();
 }