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);                   
                }



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值