Skip to content

今日头条Api分析

iMeiji edited this page Dec 17, 2016 · 9 revisions

今日头条Api分析

获取指定类型的新闻

普通用法

http://toutiao.com/api/article/recent/?source=2&category=类型&as=A1D5D87595C3287

例如获取热点新闻

http://toutiao.com/api/article/recent/?source=2&category=news_hot&as=A1D5D87595C3287

其中 category 指类型 as 值随机生成 感兴趣的自己去抓取
得到的信息为

{
  "has_more": true,
  "message": "success",
  "data": [
    {
      "media_name": "侠客岛",
      "abstract": "今天又有大新闻啦。据美国多家媒体的消息, 12月15日,中国海军在南海趁美国一艘无人水下潜航器(UUV)故障之机,抢在美军打捞人员之前将其捞走。",
      "impression_count": 7433280,
      "image_list": [
        {
          "url": "http://p1.pstatp.com/list/134b00048dd993d77429"
        },
        {
          "url": "http://p3.pstatp.com/list/1349000017bb1b3c7366"
        },
        {
          "url": "http://p3.pstatp.com/list/134c0003788b24d74346"
        }
      ],
      "media_avatar_url": "http://p3.pstatp.com/large/1731/4112623237",
      "external_visit_count": 14999,
      "article_type": 0,
      "more_mode": true,
      "tag": "news_military",
      "is_favorite": 0,
      "has_m3u8_video": 0,
      "keywords": "南海诸岛,南海,美国,专属经济区,公约,国际法",
      "has_mp4_video": 0,
      "favorite_count": 1059,
      "display_url": "http://toutiao.com/group/6365056560833659137/",
      "article_sub_type": 0,
      "bury_count": 9,
      "title": "美国想在南海下黑手,结果被中国抓个正着!这下送礼了",
      "datetime": "2016-12-17 22:27",
      "has_video": false,
      "share_url": "http://toutiao.com/group/6365056560833659137/?iid=41507200127&app=news_article",
      "id": 6365056560833659000,
      "source": "侠客岛",
      "comment_count": 17,
      "article_url": "http://toutiao.com/group/6365056560833659137/",
      "create_time": 1481980801,
      "recommend": 0,
      "tips": 0,
      "aggr_type": 1,
      "item_source_url": "/item/6365059050404577794/",
      "media_url": "http://toutiao.com/m3741758306/",
      "display_time": 1481980795,
      "publish_time": 1481980795,
      "go_detail_count": 504591,
      "group_flags": 2,
      "middle_mode": false,
      "display_title": " ",
      "gallary_image_count": 3,
      "item_seo_url": "/item/6365059050404577794/",
      "tag_id": 6365056560833659000,
      "source_url": "/group/6365056560833659137/",
      "article_genre": "article",
      "large_mode": false,
      "item_id": 6365059050404578000,
      "natant_level": 0,
      "is_digg": 0,
      "seo_url": "/group/6365056560833659137/",
      "repin_count": 1059,
      "url": "http://toutiao.com/group/6365056560833659137/",
      "level": 0,
      "digg_count": 55,
      "behot_time": 1481984828,
      "hot": 0,
      "preload_web": 2,
      "comments_count": 17,
      "has_image": true,
      "is_bury": 0,
      "group_id": 6365056560833659000,
      "middle_image": {
        "url": "http://p1.pstatp.com/list/134b00048dd993d77429",
        "width": 415,
        "url_list": [
          {
            "url": "http://p1.pstatp.com/list/134b00048dd993d77429"
          },
          {
            "url": "http://pb3.pstatp.com/list/134b00048dd993d77429"
          },
          {
            "url": "http://pb3.pstatp.com/list/134b00048dd993d77429"
          }
        ],
        "uri": "list/134b00048dd993d77429",
        "height": 536
      }
    }
  ],
  "next": {
    "max_behot_time": 1481984828
  }
}

我们要获取的新闻都在 data 数组里, 这里我只罗列了部分

以下给出部分类型 仅供参考

'推荐': '__all__',
'热点': 'news_hot',
'社会': 'news_society',
'娱乐': 'news_entertainment',
'科技': 'news_tech',
'军事': 'news_military',
'体育': 'news_sports'
'汽车': 'news_car',
'财经': 'news_finance',
'国际': 'news_world',
'时尚': 'news_fashion',
'旅游': 'news_travel',
'探索': 'news_discovery',
'育儿': 'news_baby',
'养生': 'news_regimen',
'故事': 'news_story',
'美文': 'news_essay',
'游戏': 'news_game',
'历史': 'news_history',
'美食': 'news_food',

高级用法

http://toutiao.com/api/article/recent/?source=2&category=news_hot&as=A105177907376A5&cp=5797C7865AD54E1&count=20&offset=0&_=1481986412
  • category 指类型
  • as 随机生成
  • cp 随机生成
  • count 获取文章数量
  • offset 偏移量
  • _=max_behot_time

获取文章评论

http://www.toutiao.com/api/comment/list/?group_id=头条号&item_id=文章号&offset=偏移量&count=数量

例如获取 美国无人潜航器被中国抓获引爆网络 这篇新闻的评论

http://www.toutiao.com/api/comment/list/?group_id=6364965628189327618&item_id=6364969235889783298&offset=0&count=10

其中 group_iditem_id 可以从上面的Api获取
得到的信息为

{
    "message": "success",
    "data": {
        "has_more": true,
        "total": 2410,
        "comments": [
            {
                "text": "中国是一个负责任的大国,只要美方提供证据证明这东西是美国的,中国可以归还。流程是:美方提供生产厂家原始记录、生产编号,该型号潜航器的设计图纸,以及该次海洋调查任务的详细说明、行动计划等等。中方需要半年左右的调查就可以了。",
                "digg_count": 4351,
                "reply_data": {
                    "reply_list": []
                },
                "reply_count": 176,
                "create_time": 1481964505,
                "user": {
                    "avatar_url": "http://p0.pstatp.com/origin/3793/3131589739",
                    "user_id": 6180186929,
                    "name": "hanxinping1969"
                },
                "dongtai_id": 7105200091,
                "user_digg": 0,
                "id": 52960355361
            }
        ]
    }
}
Clone this wiki locally