コード例 #1
0
        static async Task <MyResp> GetProductAsync(string path)
        {
            MyResp myresp = new MyResp();
            HttpResponseMessage response = await client.GetAsync("youtube/v3/search?part=snippet&channelId=UCPXBKQxddbDqwr5G8kTaKVg&maxResults=1&order=date&key=AIzaSyB9DJyO6YCKnmllKkYLuykCMbSqTkwRK-A&type=video");

            if (response.IsSuccessStatusCode)
            {
                //string temp = response.Content.ToString();
                //Console.Write(temp);

                //JObject search = JObject.Parse(temp);

                //JToken results = search["regionCode"];



                //items = results.ToObject<Product>();
                myresp = await response.Content.ReadAsAsync <MyResp>();



                //product = await response.Content.ReadAsAsync<Product>();

                //string data = await response.Content.ReadAsStringAsync();
                //use JavaScriptSerializer from System.Web.Script.Serialization
                //JavaScriptSerializer JSserializer = new JavaScriptSerializer();
                //deserialize to your class
                //product = JSserializer.Deserialize<Product>(data);
            }
            return(myresp);
        }
コード例 #2
0
        static async Task RunAsync()
        {
            // Update port # in the following line.
            client.BaseAddress = new Uri("https://www.googleapis.com/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            try
            {
                // Create a new product
                MyResp myresp = new MyResp();

                /*  VideoInfo vI = new VideoInfo()
                 * {
                 *    videoId = "g";
                 * }; */

                var url = new Uri("https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCPXBKQxddbDqwr5G8kTaKVg&maxResults=1&order=date&key=AIzaSyB9DJyO6YCKnmllKkYLuykCMbSqTkwRK-A&type=video");
                Console.WriteLine($"Created at {url}");

                // Get the product
                myresp = await GetProductAsync(url.PathAndQuery);

                ShowProduct(myresp);

                /* // Update the product
                 * Console.WriteLine("Updating price...");
                 * product.Price = 80;
                 * await UpdateProductAsync(product);
                 *
                 * // Get the updated product
                 * product = await GetProductAsync(url.PathAndQuery);
                 * ShowProduct(product);
                 *
                 * // Delete the product
                 * var statusCode = await DeleteProductAsync(product.Id);
                 * Console.WriteLine($"Deleted (HTTP Status = {(int)statusCode})"); */
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
コード例 #3
0
 static void ShowProduct(MyResp myresp)
 {
     Console.WriteLine($"Name: {myresp.items[0].id.videoId} ");
 }