Skip to content
StupidL edited this page Aug 21, 2016 · 1 revision

知乎专栏最新API

众所周知,知乎并没有公开API。
网上找到的知乎专栏API至少都是几个月之前的,知乎的API可能会略有调整,为了抓取最新的API,我决定自己抓包分析。
抓包分析的时间为2016-08-21.

大家可以和这篇分析对比,看看有什么不一样的地方。知乎专栏API

获取专栏的信息

获取专栏信息的URL为:

http://zhuanlan.zhihu.com/api/columns/{name}    

{name}表示的是专栏的名称,比如: wooyun
所以完整的URL为:

http://zhuanlan.zhihu.com/api/columns/wooyun  

利用Chrome浏览器提供的开发者工具,进行抓包,可以得到以下JSON数据:

{
  "followersCount": 36694,
  "creator": {
    "profileUrl": "https://www.zhihu.com/people/____",
    "bio": "I can't",
    "hash": "37841ec3e75e6583e627f64a21343b4d",
    "name": "\u957f\u77ed\u77ed",
    "isOrg": false,
    "slug": "____",
    "avatar": {
      "id": "6c83b4b34",
      "template": "https://pic1.zhimg.com/{id}_{size}.jpg"
    },
    "description": ""
  },
  "topics": [
    {
      "url": "https://www.zhihu.com/topic/19670074",
      "id": "19670074",
      "name": "\u4e4c\u4e91 (WooYun)"
    },
    {
      "url": "https://www.zhihu.com/topic/19554927",
      "id": "19554927",
      "name": "\u7f51\u7edc\u5b89\u5168"
    }
  ],
  "activateState": "activated",
  "href": "/api/columns/wooyun",
  "acceptSubmission": true,
  "firstTime": false,
  "postTopics": [
    {
      "postsCount": 1,
      "id": 99,
      "name": "\u4e92\u8054\u7f51"
    },
    {
      "postsCount": 1,
      "id": 225,
      "name": "\u524d\u7aef\u5f00\u53d1"
    },
    {
      "postsCount": 1,
      "id": 383,
      "name": "\u9006\u5411\u5de5\u7a0b"
    },
    {
      "postsCount": 1,
      "id": 488,
      "name": "\u624b\u673a"
    },
    {
      "postsCount": 4,
      "id": 1567,
      "name": "\u7f51\u7edc\u5b89\u5168"
    },
    {
      "postsCount": 1,
      "id": 2155,
      "name": "\u4e2d\u56fd\u79fb\u52a8"
    },
    {
      "postsCount": 1,
      "id": 2340,
      "name": "IPTV"
    },
    {
      "postsCount": 1,
      "id": 2593,
      "name": "Internet Explorer"
    },
    {
      "postsCount": 1,
      "id": 2666,
      "name": "OAuth"
    },
    {
      "postsCount": 2,
      "id": 2823,
      "name": "\u9ed1\u5ba2 (Hacker)"
    },
    {
      "postsCount": 1,
      "id": 3631,
      "name": "\u8def\u7531\u5668"
    },
    {
      "postsCount": 1,
      "id": 3646,
      "name": "Java"
    },
    {
      "postsCount": 1,
      "id": 5120,
      "name": "\u7535\u4fe1"
    },
    {
      "postsCount": 1,
      "id": 5833,
      "name": "\u7528\u6237\u6570\u636e"
    },
    {
      "postsCount": 1,
      "id": 11096,
      "name": "\u4f18\u6b65\uff08Uber\uff09"
    },
    {
      "postsCount": 1,
      "id": 11587,
      "name": "XSS"
    },
    {
      "postsCount": 1,
      "id": 11843,
      "name": "\u673a\u9876\u76d2"
    },
    {
      "postsCount": 1,
      "id": 12741,
      "name": "\u8bc8\u9a97"
    },
    {
      "postsCount": 1,
      "id": 16275,
      "name": "\u7ffb\u8bd1\u4e66\u7c4d"
    },
    {
      "postsCount": 1,
      "id": 16898,
      "name": "WebKit"
    },
    {
      "postsCount": 3,
      "id": 17686,
      "name": "Android"
    },
    {
      "postsCount": 1,
      "id": 18104,
      "name": "\u79fb\u52a8\u5b89\u5168"
    },
    {
      "postsCount": 1,
      "id": 19259,
      "name": "\u77ed\u4fe1\u5e73\u53f0"
    },
    {
      "postsCount": 1,
      "id": 22208,
      "name": "\u7f51\u7edc\u6e17\u900f"
    },
    {
      "postsCount": 1,
      "id": 29478,
      "name": "\u7f51\u7edc\u9493\u9c7c\u8bc8\u9a97"
    },
    {
      "postsCount": 1,
      "id": 40041,
      "name": "\u4e4c\u4e91 (WooYun)"
    },
    {
      "postsCount": 1,
      "id": 46204,
      "name": "Android \u7b2c\u4e09\u65b9 ROM"
    },
    {
      "postsCount": 1,
      "id": 56158,
      "name": "\u77ed\u4fe1\u9a8c\u8bc1\u7801"
    },
    {
      "postsCount": 2,
      "id": 120695,
      "name": "\u4f2a\u57fa\u7ad9"
    },
    {
      "postsCount": 1,
      "id": 136592,
      "name": "LTE-EPC"
    },
    {
      "postsCount": 1,
      "id": 141836,
      "name": "Web \u6f0f\u6d1e"
    }
  ],
  "pendingName": "",
  "avatar": {
    "id": "0ec77eef1",
    "template": "https://pic2.zhimg.com/{id}_{size}.jpg"
  },
  "canManage": false,
  "description": "\u5199\u70b9\u6709\u7528\u7684\u4e1c\u897f\u3002",
  "pendingTopics": [],
  "nameCanEditUntil": 0,
  "reason": "",
  "banUntil": 0,
  "slug": "wooyun",
  "name": "\u4e4c\u4e91\u541b",
  "url": "/wooyun",
  "intro": "\u5199\u70b9\u6709\u7528\u7684\u4e1c\u897f\u3002",
  "topicsCanEditUntil": 0,
  "activateAuthorRequested": "none",
  "commentPermission": "anyone",
  "following": false,
  "postsCount": 54,
  "canPost": false
}  

结果与上述文章大同小异,多了几个无关紧要的字段而已。
其中:
"followersCount": 关注该专栏的人数
"creator": 该专栏的创建者
"topics": 该专栏包含的话题
"avatar": 头像信息,将id拼接到template里面就可以访问头像地址以获得头像,{size}有三种选择:l\m\s
"description": 专栏的介绍
"intro": 专栏的介绍(并不确定)

获取专栏中的文章

获取专栏中的文章列表的URL为:

http://zhuanlan.zhihu.com/api/columns/{name}/posts?limit={limit}&offset={offset}  

其中:
{name}表示: 专栏的名称,比如: wooyun
{limit}表示: 获取文章的上限,比如: 10
{offset}表示: 从哪里开始获取,比如: 5

还是以wooyun为例,完整的URL为:

http://zhuanlan.zhihu.com/api/columns/wooyun/posts?limit=2&offset=0  

获得的返回结果如下:

[
  {
    "isTitleImageFullScreen": false,
    "rating": "none",
    "sourceUrl": "",
    "publishedTime": "2016-06-08T18:07:21+08:00",
    "links": {
      "comments": "/api/posts/21308493/comments"
    },
    "author": {
      "profileUrl": "https://www.zhihu.com/people/fenggou",
      "bio": "\u4fe1\u606f\u5b89\u5168\uff0c\u9e21\u5c3e\u9152\uff0c\u7535\u5409\u4ed6\uff0c\u6444\u5f71\u3002",
      "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
      "name": "fenggou",
      "isOrg": false,
      "slug": "fenggou",
      "avatar": {
        "id": "939c20127",
        "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
      },
      "description": "\u5199\u6587\u5b57\u5bf9\u4e8e\u6211\u6765\u8bf4\u633a\u75db\u82e6\u7684\u3002"
    },
    "url": "/p/21308493",
    "title": "\u9ed1\u5ba2\u5bf9 Uber \u4f7f\u51fa\u300c\u6c34\u571f\u4e0d\u670d\u300d\u6280\u80fd\uff0c\u7528\u6237\u94b1\u5305\u53d7\u523010000\u70b9\u4f24\u5bb3",
    "titleImage": "https://pic4.zhimg.com/031e06ee614489dcfbda68218be69893_r.jpg",
    "summary": "",
    "content": "内容太长不予显示",
    "state": "published",
    "href": "/api/posts/21308493",
    "meta": {
      "previous": null,
      "next": null
    },
    "commentPermission": "anyone",
    "snapshotUrl": "",
    "canComment": false,
    "slug": 21308493,
    "commentsCount": 57,
    "likesCount": 558
  },
  {
    "isTitleImageFullScreen": false,
    "rating": "none",
    "sourceUrl": "",
    "publishedTime": "2016-04-07T16:50:52+08:00",
    "links": {
      "comments": "/api/posts/20694237/comments"
    },
    "author": {
      "profileUrl": "https://www.zhihu.com/people/fenggou",
      "bio": "\u4fe1\u606f\u5b89\u5168\uff0c\u9e21\u5c3e\u9152\uff0c\u7535\u5409\u4ed6\uff0c\u6444\u5f71\u3002",
      "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
      "name": "fenggou",
      "isOrg": false,
      "slug": "fenggou",
      "avatar": {
        "id": "939c20127",
        "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
      },
      "description": "\u5199\u6587\u5b57\u5bf9\u4e8e\u6211\u6765\u8bf4\u633a\u75db\u82e6\u7684\u3002"
    },
    "url": "/p/20694237",
    "title": "\u6df1\u5ea6\u63ed\u79d8\uff1a\u4f2a\u57fa\u7ad9\u77ed\u4fe1\u8bc8\u9a97\u4ea7\u4e1a\u4f20\u5947\u59cb\u672b\uff01",
    "titleImage": "https://pic2.zhimg.com/263519b85474c577e78809849f6e1761_r.jpg",
    "summary": "",
    "content": "内容太长不予显示",
    "state": "published",
    "href": "/api/posts/20694237",
    "meta": {
      "previous": null,
      "next": null
    },
    "commentPermission": "anyone",
    "snapshotUrl": "",
    "canComment": false,
    "slug": 20694237,
    "commentsCount": 74,
    "likesCount": 1133
  }
]  

上面的结果就是:从该专栏的文章列表中,从第一篇开始,取出2篇文章。
其中:
"links"表示: 该文章的评论列表,写App的时候要是想显示评论,则用得上它
"author"表示: 文章的作者
"title"表示: 文章的标题
"titleImage"表示: 标题的配图,一般文章的展示页面会有一张图片,在标题的下面
"content"表示: 文章的具体内容
"commentsCount": 评论数量
"likesCount": 点赞数量
"slug": 根据slug就可以访问单独的文章

获取文章的详情

获取文章详情的URL为:

https://zhuanlan.zhihu.com/api/posts/{slug}  

其中:
{slug}表示: 文章的编号
以上面得到的两篇文章中的第一篇文章为例,完整的URL为:

https://zhuanlan.zhihu.com/api/posts/21308493  

抓包获得的结果如下:

{
  "isTitleImageFullScreen": false,
  "rating": "none",
  "titleImage": "https://pic4.zhimg.com/031e06ee614489dcfbda68218be69893_r.jpg",
  "links": {
    "comments": "/api/posts/21308493/comments"
  },
  "reviewers": [],
  "topics": [
    {
      "url": "https://www.zhihu.com/topic/19583569",
      "id": "19583569",
      "name": "\u4f18\u6b65\uff08Uber\uff09"
    },
    {
      "url": "https://www.zhihu.com/topic/19554927",
      "id": "19554927",
      "name": "\u7f51\u7edc\u5b89\u5168"
    },
    {
      "url": "https://www.zhihu.com/topic/19567675",
      "id": "19567675",
      "name": "\u7528\u6237\u6570\u636e"
    }
  ],
  "titleImageSize": {
    "width": 997,
    "height": 559
  },
  "href": "/api/posts/21308493",
  "author": {
    "profileUrl": "https://www.zhihu.com/people/fenggou",
    "bio": "\u4fe1\u606f\u5b89\u5168\uff0c\u9e21\u5c3e\u9152\uff0c\u7535\u5409\u4ed6\uff0c\u6444\u5f71\u3002",
    "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
    "name": "fenggou",
    "isOrg": false,
    "badge": {
      "identity": null,
      "best_answerer": null
    },
    "slug": "fenggou",
    "avatar": {
      "id": "939c20127",
      "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
    },
    "description": "\u5199\u6587\u5b57\u5bf9\u4e8e\u6211\u6765\u8bf4\u633a\u75db\u82e6\u7684\u3002"
  },
  "column": {
    "slug": "wooyun",
    "name": "\u4e4c\u4e91\u541b"
  },
  "tipjarState": "inactivated",
  "content": "内容太长不予显示",
  "state": "published",
  "sourceUrl": "",
  "pageCommentsCount": 57,
  "canComment": false,
  "snapshotUrl": "",
  "slug": 21308493,
  "publishedTime": "2016-06-08T18:07:21+08:00",
  "url": "/p/21308493",
  "title": "\u9ed1\u5ba2\u5bf9 Uber \u4f7f\u51fa\u300c\u6c34\u571f\u4e0d\u670d\u300d\u6280\u80fd\uff0c\u7528\u6237\u94b1\u5305\u53d7\u523010000\u70b9\u4f24\u5bb3",
  "lastestLikers": [
    {
      "profileUrl": "https://www.zhihu.com/people/andy-zhang-71-55",
      "bio": "\u7f18\u8d77\u6027\u7a7a\u5565\u610f\u601d\uff1f",
      "hash": "993fa341e49e521ec2a2721d2afc4c24",
      "name": "\u7f18\u5fc3",
      "isOrg": false,
      "slug": "andy-zhang-71-55",
      "avatar": {
        "id": "c00959afcd99541d9314a859b3e2aee2",
        "template": "https://pic3.zhimg.com/{id}_{size}.jpg"
      },
      "description": "\u4e0a\u58eb\u95fb\u9053\uff0c\u52e4\u800c\u884c\u4e4b\uff1b\u4e2d\u58eb\u95fb\u9053\uff0c\u82e5\u5b58\u82e5\u4ea1\uff1b\u4e0b\u58eb\u95fb\u9053\uff0c\u5927\u7b11\u4e4b\u3002\u4e0d\u7b11\u4e0d\u8db3\u4ee5\u4e3a\u9053\u3002"
    },
    {
      "profileUrl": "https://www.zhihu.com/people/shi-nian-yijian-85",
      "bio": null,
      "hash": "2172b9a181748e78501d193f4ffd8673",
      "name": "\u5341\u5e74\u4e00\u5251",
      "isOrg": false,
      "slug": "shi-nian-yijian-85",
      "avatar": {
        "id": "e788cbf2cb0f3cf0d949d1b1770f18d6",
        "template": "https://pic3.zhimg.com/{id}_{size}.jpg"
      },
      "description": ""
    },
    {
      "profileUrl": "https://www.zhihu.com/people/bigcao",
      "bio": "\u7ea0\u7ed3\u7efc\u5408\u4f53",
      "hash": "3b581cdfa5c16265a5582fc20a04485f",
      "name": "big\u66f9",
      "isOrg": false,
      "slug": "bigcao",
      "avatar": {
        "id": "bc5d33daaa9c0d9a34193e295f289d4f",
        "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
      },
      "description": "\u60f3\u8981\u53d8\u6210\u4e00\u68f5\u51ac\u5b63\u7684\u6811"
    },
    {
      "profileUrl": "https://www.zhihu.com/people/dan-ding-9",
      "bio": "\u8fd9\u4e16\u95f4\u552f\u6709\u68a6\u60f3\u4e0e\u597d\u59d1\u5a18\u4e0d\u53ef\u8f9c\u8d1f",
      "hash": "b2b1269d7e6b39e914cb553e1d930ec0",
      "name": "\u6de1\u5b9a",
      "isOrg": false,
      "slug": "dan-ding-9",
      "avatar": {
        "id": "3b697b059aa5956aa2159312c12cfb20",
        "template": "https://pic1.zhimg.com/{id}_{size}.png"
      },
      "description": ""
    },
    {
      "profileUrl": "https://www.zhihu.com/people/eve-86-33",
      "bio": "",
      "hash": "87b67a74852cac9527023a4d63878729",
      "name": "eve",
      "isOrg": false,
      "slug": "eve-86-33",
      "avatar": {
        "id": "29a94cbd32ca8d3d49a010342da1648d",
        "template": "https://pic2.zhimg.com/{id}_{size}.jpg"
      },
      "description": "\u67d0\u5927\u5b66\u5b66\u751f"
    }
  ],
  "summary": "<img src=\"https://pic2.zhimg.com/2e624cd7e8952fd8c13f3cd552ce77a1_200x112.jpg\" data-rawwidth=\"1280\" data-rawheight=\"1136\" class=\"origin_image inline-img zh-lightbox-thumb\" data-original=\"https://pic2.zhimg.com/2e624cd7e8952fd8c13f3cd552ce77a1_r.jpg\">\u5c0f\u65f6\u5019\u770b\u79d1\u5e7b\u6545\u4e8b\uff0c\u4f5c\u8005\u90fd\u559c\u6b22\u628a\u706b\u661f\u89c6\u4e3a\u813e\u6c14\u66b4\u8e81\u7684\u90bb\u5c45\uff0c\u4e00\u8a00\u4e0d\u5408\u5c31\u8981\u73a9\u8f6c\u5730\u7403\u3002\u4f46\u6bcf\u5f53\u5730\u7403\u5c06\u88ab\u63a8\u5012\u7684\u5173\u952e\u65f6\u523b\uff0c\u706b\u661f\u4eba\u7adf\u7136\u6279\u91cf\u6251\u8857\uff0c\u539f\u56e0\u662f\u6c34\u571f\u4e0d\u670d\u88ab\u5730\u7403\u7ec6\u83cc\u611f\u67d3\uff0c\u6700\u7ec8\u573a\u9762\u53d8\u6210\u4eba\u6c11\u7fa4\u4f17\u54c4\u62a2\u6563\u843d\u5728\u5730\u4e0a\u7684\u516b\u722a\u9c7c\u6e29\u99a8\u7ed3\u5c3e\u3002\u8fd9\u4e9b\u5957\u8def\u7ed9\u6211\u7559\u4e0b\u6df1\u523b\u5370\u8c61\uff0c\u7279\u522b\u2026",
  "reviewingCommentsCount": 0,
  "meta": {
    "previous": {
      "isTitleImageFullScreen": false,
      "rating": "none",
      "titleImage": "https://pic2.zhimg.com/263519b85474c577e78809849f6e1761_r.jpg",
      "links": {
        "comments": "/api/posts/20694237/comments"
      },
      "topics": [
        {
          "url": "https://www.zhihu.com/topic/19588459",
          "id": "19588459",
          "name": "\u8bc8\u9a97"
        },
        {
          "url": "https://www.zhihu.com/topic/19905972",
          "id": "19905972",
          "name": "\u4f2a\u57fa\u7ad9"
        },
        {
          "url": "https://www.zhihu.com/topic/19558642",
          "id": "19558642",
          "name": "\u9ed1\u5ba2 (Hacker)"
        }
      ],
      "href": "/api/posts/20694237",
      "author": {
        "profileUrl": "https://www.zhihu.com/people/fenggou",
        "bio": "\u4fe1\u606f\u5b89\u5168\uff0c\u9e21\u5c3e\u9152\uff0c\u7535\u5409\u4ed6\uff0c\u6444\u5f71\u3002",
        "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
        "name": "fenggou",
        "isOrg": false,
        "slug": "fenggou",
        "avatar": {
          "id": "939c20127",
          "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
        },
        "description": "\u5199\u6587\u5b57\u5bf9\u4e8e\u6211\u6765\u8bf4\u633a\u75db\u82e6\u7684\u3002"
      },
      "column": {
        "slug": "wooyun",
        "name": "\u4e4c\u4e91\u541b"
      },
      "content": "内容太长不予显示",
      "state": "published",
      "sourceUrl": "",
      "pageCommentsCount": 0,
      "canComment": false,
      "snapshotUrl": "",
      "slug": 20694237,
      "publishedTime": "2016-04-07T16:50:52+08:00",
      "url": "/p/20694237",
      "title": "\u6df1\u5ea6\u63ed\u79d8\uff1a\u4f2a\u57fa\u7ad9\u77ed\u4fe1\u8bc8\u9a97\u4ea7\u4e1a\u4f20\u5947\u59cb\u672b\uff01",
      "summary": "<b>\u672c\u6587\u611f\u8c22\u4e4c\u4e91Drops\u56e2\u961f\u63d0\u4f9b\u7684\u60c5\u62a5\u652f\u6301\uff01</b>\u8fd1\u4e9b\u5e74\u56e0\u4f2a\u57fa\u7ad9\u77ed\u4fe1\u8bc8\u9a97\u7684\u5d1b\u8d77\u5bf9\u7528\u6237\u9020\u6210\u4e86\u60e8\u75db\u7684\u7ecf\u6d4e\u635f\u5931\uff0c\u5982\u4eca\u76f8\u5173\u90e8\u95e8\u4e25\u6253\u4f2a\u57fa\u7ad9\u77ed\u4fe1\u8bc8\u9a97\u884c\u4e1a\u5df2\u53d6\u5f97\u521d\u6b65\u6210\u6548\uff0c\u4f46\u4ecd\u6709\u9ed1\u4ea7\u56e2\u4f19\u94e4\u800c\u8d70\u9669\u7ee7\u7eed\u4f5c\u6848\uff0c\u5bfc\u81f4\u76d7\u5237\u4e8b\u4ef6\u8fd8\u662f\u4e0d\u65ad\u6d8c\u73b0\u3002\u4e4c\u4e91\u541b\u548c\u884c\u4e1a\u90fd\u66fe\u62a5\u9053\u8fc7\u4e00\u4e9b\u4f2a\u57fa\u7ad9\u8bc8\u9a97\u2026",
      "reviewingCommentsCount": 0,
      "meta": {
        "previous": null,
        "next": null
      },
      "commentPermission": "anyone",
      "commentsCount": 0,
      "likesCount": 0
    },
    "next": null
  },
  "commentPermission": "anyone",
  "commentsCount": 57,
  "likesCount": 558
}  

上面的一些字段不需要解释了。值得注意的是:
meta中的previous: 应该是指的前一篇文章(这里的逻辑不是很清楚)
meta中的next: 应该是指的之后一篇文章

至此,专栏的API以及全部知道了。接下来就是如何编码实现了。

编写客户端思路

根据上面的API分析,可以得知,应该创建以下几个Java Bean:

  • Column —— 专栏
  • Article —— 文章
  • Author(Creator) —— 作者
  • Avatar —— 头像
  • Topic —— 话题
  • 其他你所需要的

写完Java Bean之后,接下来的任务就是根据API发送Http请求,解析返回的JSON数据,映射到Java Bean中,然后将Java Bean携带的数据 用适配器适配到UI。大致的工作就是这样。
我的想法是,使用OKHttp、Gson、Retrofit三个三方库一起实现。这三个库我也没用过,正在研究中。
另:
这个客户端的编写我已经完成了UI部分,Java Bean也写好了,接下来就是数据操作这一块。
项目已经放到Github: StupidL
欢迎大家fork。

邮箱

luozhouyang0528@gmail.com