C# WebApi 獲取今日頭條新聞代碼

注意:當前方法通過【聚合數據】中的今日頭條API實現。

                var key ="聚合數據獲取到的KEY";
                var typeCode ="聚合數據中的新聞分類,例如:top代表頭條,tiyu代表體育,yule代表娛樂等。";
                string url = string.Format("http://v.juhe.cn/toutiao/index?type={0}&key={1}",typeCode,key);
                System.Net.WebClient web = new System.Net.WebClient();
                var data = web.DownloadData(url);
                var dataStr = System.Text.Encoding.UTF8.GetString(data);
                MJuHeNewsView result = JsonToObject<MJuHeNewsView>(dataStr);
                if (result.reason != "成功的返回")
                    return;
                foreach (var news in result.result.data)
                {
                    var n = (new TBLNews()
                    {
                        Uniquekey = news.uniquekey,
                        TypeCode = item.TypeCode,
                        Title = news.title,
                        Date = news.date,
                        Category = news.category,
                        Author_name = news.author_name,
                        Url = news.url,
                        Thumbnail_Pic_S = news.thumbnail_pic_s,
                        Thumbnail_Pic_S2 = news.thumbnail_pic_s02,
                        Thumbnail_Pic_S3 = news.thumbnail_pic_s03,
                        Status = (int)TBLNews.EnumStatus.No,
                        Clicks = 0
                    });
                     //將數據插入到數據庫
                    DB.TBLNews.Add(n);                   
                }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章