微博用户API分析

发布于 / 教程 / 0 条评论

微博提供了公共的api 但是授权麻烦还有诸多限制,对于获取用户基础信息这么简单的需求有木有其他方式实现呢?于是习惯性的打开了控制台….

最近做的一个小工具:通过微博图片地址寻找发图人,用到了部分用户信息,你可以查看效果:【谁发的图?】

准备

以微博用户:walking300 为例,其uid为5695741907
经过测试,找到了如下接口:


https://m.weibo.cn/api/container/getIndex?is_all[]=1&is_all[]=1&jumpfrom=weibocom&type=uid&value=5695741907

接口返回:


{
    "ok": 1,
    "data": {
        "userInfo": {
            "id": 5695741907,
            "screen_name": "walking300",
            "profile_image_url": "https://tva2.sinaimg.cn/crop.133.37.333.333.180/006dsKEXjw8evu3tzk8irj30go0bctac.jpg",
            "profile_url": "https://m.weibo.cn/u/5695741907?uid=5695741907&luicode=10000011&lfid=1005055695741907",
            "statuses_count": 63,
            "verified": false,
            "verified_type": -1,
            "close_blue_v": false,
            "description": "spg walking 300",
            "gender": "m",
            "mbtype": 0,
            "urank": 9,
            "mbrank": 0,
            "follow_me": false,
            "following": true,
            "followers_count": 1938,
            "follow_count": 62,
            "cover_image_phone": "https://tva1.sinaimg.cn/crop.0.0.640.640.640/549d0121tw1egm1kjly3jj20hs0hsq4f.jpg",
            "avatar_hd": "https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/orj480/006dsKEXjw8evu3tzk8irj30go0bctac.jpg",
            "like": false,
            "like_me": false,
            "toolbar_menus": [
                {
                    "type": "profile_follow",
                    "name": "已关注",
                    "sub_type": 1,
                    "params": {
                        "uid": 5695741907
                    },
                    "actionlog": {
                        "act_code": "594",
                        "fid": "2307745695741907",
                        "oid": "1005055695741907",
                        "cardid": "230774_-_WEIBO_INDEX_PROFILE_FOLLOW",
                        "ext": "uid:3219152553|ouid:5695741907|ptype:0|verified_type:-1|load_read_level:3|btn_name:关注"
                    }
                },
                {
                    "type": "link",
                    "name": "聊天",
                    "params": {
                        "scheme": "sinaweibo://messagelist?uid=5695741907&nick=walking300&verified_type=-1"
                    },
                    "actionlog": {
                        "act_code": "594",
                        "fid": "2307745695741907",
                        "oid": "messagelist",
                        "cardid": "230774_-_WEIBO_INDEX_PROFILE_CHAT",
                        "ext": "uid:3219152553|ouid:5695741907|ptype:0|verified_type:-1|load_read_level:3|btn_name:聊天"
                    },
                    "scheme": "https://m.weibo.cn/msg/chat?uid=5695741907&nick=walking300&verified_type=-1&luicode=10000011&lfid=1005055695741907"
                },
                {
                    "type": "toolbar_menu_list",
                    "name": "他的热门",
                    "params": {
                        "menu_list": [
                            {
                                "type": "link",
                                "name": "全部微博",
                                "params": {
                                    "scheme": "sinaweibo://cardlist?containerid=2304135695741907_-_WEIBO_SECOND_PROFILE_WEIBO"
                                },
                                "actionlog": {
                                    "act_code": "594",
                                    "fid": "2307745695741907",
                                    "oid": "2304135695741907_-_WEIBO_SECOND_PROFILE_WEIBO",
                                    "cardid": "230774_-_WEIBO_INDEX_PROFILE_ALLWEIBO",
                                    "ext": "uid:3219152553|ouid:5695741907|ptype:0|verified_type:-1|load_read_level:3|btn_name:全部微博"
                                },
                                "scheme": "https://m.weibo.cn/p/index?containerid=2304135695741907_-_WEIBO_SECOND_PROFILE_WEIBO&luicode=10000011&lfid=1005055695741907"
                            }
                        ]
                    },
                    "actionlog": {
                        "act_code": "594",
                        "fid": "2307745695741907",
                        "oid": "1005055695741907",
                        "cardid": "230774_-_WEIBO_INDEX_PROFILE_BTN_ALL",
                        "ext": "uid:3219152553|ouid:5695741907|ptype:0|verified_type:-1|load_read_level:3|btn_name:他的热门"
                    }
                }
            ]
        },
        "fans_scheme": "https://m.weibo.cn/p/index?containerid=231051_-_fansrecomm_-_5695741907&luicode=10000011&lfid=1005055695741907",
        "follow_scheme": "https://m.weibo.cn/p/index?containerid=231051_-_followersrecomm_-_5695741907&luicode=10000011&lfid=1005055695741907",
        "tabsInfo": {
            "selectedTab": 1,
            "tabs": [
                {
                    "title": "主页",
                    "tab_type": "profile",
                    "containerid": "2302835695741907"
                },
                {
                    "title": "微博",
                    "tab_type": "weibo",
                    "containerid": "1076035695741907",
                    "url": "/index/my"
                }
            ]
        },
        "showAppTips": 1,
        "scheme": "sinaweibo://userinfo?uid=5695741907&luicode=10000011&lfid=2302835695741907&featurecode="
    }
}

在返回的参数中我们找到:


 {
                    "title": "主页",
                    "tab_type": "profile",
                    "containerid": "2302835695741907"
                },
                {
                    "title": "微博",
                    "tab_type": "weibo",
                    "containerid": "1076035695741907",
                   

其中【containerid】是移动端tab主页和微博下的id,通过title属性也能发现。
现在用前面的接口拼接这个containerid参数,这里我们需要用户信息,所以只拼接title为【主页】的【containerid】,
像这样:


https://m.weibo.cn/api/container/getIndex?is_all[]=1&is_all[]=1&jumpfrom=weibocom&type=uid&value=5695741907&containerid=2302835695741907

接口返回:


{
    "ok": 1,
    "data": {
        "cardlistInfo": {
            "v_p": "42",
            "cardlist_title": "",
            "desc": "",
            "show_style": 1,
            "can_shared": 0,
            "containerid": "2302835695741907",
            "cardlist_menus": [
                {
                    "type": "button_menus_refresh",
                    "name": "刷新"
                },
                {
                    "type": "gohome",
                    "name": "返回首页",
                    "params": {
                        "scheme": "sinaweibo://gotohome"
                    }
                }
            ],
            "page": null
        },
        "cards": [
            {
                "card_type": 11,
                "show_type": 2,
                "card_group": [
                    {
                        "card_type": 4,
                        "desc": "基本资料",
                        "display_arrow": 1,
                        "scheme": "https://m.weibo.cn/p/index?containerid=2302835695741907_-_INFO&title=%25E5%259F%25BA%25E6%259C%25AC%25E8%25B5%2584%25E6%2596%2599&luicode=10000011&lfid=2302835695741907"
                    },
                    {
                        "card_type": 41,
                        "item_name": "信息",
                        "item_content": "男  23岁  摩羯座  湖北 荆州",
                        "content_color_type": 0,
                        "scheme": ""
                    },
                    {
                        "card_type": 41,
                        "item_name": "注册时间",
                        "item_content": "2015-09-07",
                        "content_color_type": 0,
                        "scheme": ""
                    },
                    {
                        "card_type": 7,
                        "source": "我们都是摩羯座。"
                    }
                ]
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_USERVIDEO",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_USERVIDEO&download="
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_HOTMBLOG",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_HOTMBLOG&download="
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_HONGBAOCARD",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_HONGBAOCARD&download="
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_BESTPHOTO",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_BESTPHOTO&download="
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_USERPERSONALIZE",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_USERPERSONALIZE&download="
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_TOPICLIST",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_TOPICLIST&download="
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_ARTICLE",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_ARTICLE&download="
            },
            {
                "card_type": 6,
                "card_type_name": "查看他的全部微博",
                "itemid": "more_weibo",
                "title": "查看他的全部微博",
                "scheme": "https://m.weibo.cn/p/index?containerid=2304135695741907_-_WEIBO_SECOND_PROFILE_WEIBO&luicode=10000011&lfid=2302835695741907",
                "desc": "查看他的全部微博",
                "show_type": 0,
                "actionlog": {
                    "act_code": "695",
                    "uicode": "10000198",
                    "oid": "2304135695741907_-_WEIBO_SECOND_PROFILE_MORE_WEIBO",
                    "fid": "2302835695741907",
                    "cardid": "230283_-_WEIBO_INDEX_PROFILE_ALLWEIBO",
                    "ext": "uid:3219152553|ouid:5695741907|verified_type:-1|ptype:0|load_read_level:"
                }
            }
        ],
        "showAppTips": 0,
        "scheme": "sinaweibo://cardlist?containerid=2302835695741907&extparam=&luicode=10000011&lfid=2302835695741907&featurecode="
    }
}

现在就得到了我们在手机上第一屏看到的用户信息了,当然还没完,如果我们要获得用户所有的信息还得继续。

获取更多信息

在上述返回的json数据中找到:


  "card_group": [
                    {
                        "card_type": 4,
                        "desc": "基本资料",
                        "display_arrow": 1,
                        "scheme": "https://m.weibo.cn/p/index?containerid=2302835695741907_-_INFO&title=%25E5%259F%25BA%25E6%259C%25AC%25E8%25B5%2584%25E6%2596%2599&luicode=10000011&lfid=2302835695741907"
                    }

没错我们需要【scheme】的值:
https://m.weibo.cn/p/index?containerid=2302835695741907_-_INFO&title=%25E5%259F%25BA%25E6%259C%25AC%25E8%25B5%2584%25E6%2596%2599&luicode=10000011&lfid=2302835695741907
经过再次测试,这个地址不会直接返回json数据,而是通过另一个拼接的url 返回,实际上经过观察我们只需要替换这个【scheme】的值部分即可得到接口地址:
p/index替换为api/container/getIndex即可,所以最终的接口地址为:


https://m.weibo.cn/api/container/getIndex?containerid=2302835695741907_-_INFO&title=%25E5%259F%25BA%25E6%259C%25AC%25E8%25B5%2584%25E6%2596%2599&luicode=10000011&lfid=2302835695741907

接口返回:


{
    "ok": 1,
    "data": {
        "cardlistInfo": {
            "v_p": "42",
            "cardlist_title": "",
            "desc": "",
            "show_style": 1,
            "can_shared": 0,
            "containerid": "2302835695741907_-_INFO",
            "cardlist_menus": [
                {
                    "type": "button_menus_refresh",
                    "name": "刷新"
                },
                {
                    "type": "gohome",
                    "name": "返回首页",
                    "params": {
                        "scheme": "sinaweibo://gotohome"
                    }
                }
            ],
            "button": null,
            "page": null
        },
        "cards": [
            {
                "card_type": 11,
                "show_type": 2,
                "card_group": [
                    {
                        "card_type": 41,
                        "item_name": "昵称",
                        "item_content": "walking300"
                    },
                    {
                        "card_type": 41,
                        "item_type": "set_remark",
                        "uid": "5695741907",
                        "item_name": "Tap to set alias",
                        "item_content": "",
                        "display_arrow": 1
                    },
                    {
                        "card_type": 41,
                        "item_name": "性别",
                        "item_content": "男"
                    },
                    {
                        "card_type": 41,
                        "item_name": "所在地",
                        "item_content": "湖北 荆州"
                    },
                    {
                        "card_type": 41,
                        "item_name": "简介",
                        "item_content": "spg walking 300"
                    }
                ]
            },
            {
                "card_type": 11,
                "show_type": 2,
                "is_asyn": 0,
                "card_group": [
                    {
                        "card_type": 41,
                        "item_name": "等级",
                        "scheme": "http://level.account.weibo.cn/myrankinfo?luicode=10000011&lfid=2302835695741907_-_INFO",
                        "display_arrow": 1,
                        "item_content": "LV 9",
                        "actionlog": {
                            "act_code": "594",
                            "uicode": "10000198",
                            "oid": "http://level.account.weibo.cn/myrankinfo",
                            "fid": "2302835695741907_-_INFO",
                            "cardid": "230283_-_WEIBO_INDEX_USERINFO_URANK",
                            "ext": "uid:3219152553|ouid:5695741907|verified_type:-1|ptype:0|load_read_level:"
                        }
                    },
                    {
                        "card_type": 41,
                        "item_name": "阳光信用",
                        "item_content": "信用一般",
                        "display_arrow": 1,
                        "scheme": "https://service.account.weibo.com/sunshine/guize?sinainternalbrowser=topnav&luicode=10000011&lfid=2302835695741907_-_INFO",
                        "actionlog": {
                            "act_code": "594",
                            "uicode": "10000198",
                            "oid": "https://service.account.weibo.com/sunshine/guize?sinainternalbrowser=topnav",
                            "fid": "2302835695741907_-_INFO",
                            "cardid": "230283_-_WEIBO_INDEX_USERINFO_CREDIT",
                            "ext": "uid:3219152553|ouid:5695741907|verified_type:-1|ptype:0|load_read_level:"
                        }
                    },
                    {
                        "card_type": 41,
                        "item_name": "注册时间",
                        "item_content": "2015-09-07"
                    }
                ]
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_3861",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_3861&download="
            },
            {
                "card_type": 11,
                "is_asyn": 1,
                "itemid": "2306185695741907_-_profileinterest",
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_profileinterest&download="
            },
            {
                "card_type": 11,
                "card_type_name": "",
                "card_id": "renling",
                "title": "",
                "scheme": "",
                "card_group": [
                    {
                        "card_type": 42,
                        "desc": "签到足迹",
                        "display_type": 0,
                        "scheme": "https://m.weibo.cn/p/index?containerid=2310340013&count=5&extparam=uid%2C5695741907&needlocation=1&title=%25E7%25AD%25BE%25E5%2588%25B0%25E8%25B6%25B3%25E8%25BF%25B9&luicode=10000011&lfid=2302835695741907_-_INFO",
                        "pic": "",
                        "title_extra_text": "全部",
                        "display_arrow": 1,
                        "actionlog": {
                            "act_code": 594,
                            "fid": "2302835695741907_-_INFO",
                            "oid": "23085800245695741907",
                            "uicode": "10000198",
                            "cardid": "230283_-_WEIBO_INDEX_PROFILE_LBSZUJI",
                            "ext": "uid:3219152553;ouid:5695741907;verified_type:-1;ptype:0;load_read_level:0"
                        }
                    },
                    {
                        "card_type": 8,
                        "card_type_name": "",
                        "card_id": "renling4027990981838289",
                        "title": "",
                        "scheme": "https://m.weibo.cn/p/index?containerid=2310340006&count=10&needlocation=1&title=%25E6%25AD%25A6%25E6%25B1%2589&extparam=city%2C0027%2C5695741907&luicode=10000011&lfid=2302835695741907_-_INFO",
                        "display_arrow": 1,
                        "pic": "https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/wap180/4e704b16jw1esr3fam583j207z07zt9m.jpg",
                        "title_sub": "武汉",
                        "desc1": "今天休息了,今晚回荆州在家里呆,我很懒无法照顾自己,决定回家回爸妈的怀抱,安心直播,不贪玩了,从明天开始认真拼直播连续一个月,准备猝死了,然后福利来了,明天直播微博抽取一枚电一百分之90胜率钻石号,[喵喵][喵喵][喵喵],  ​",
                        "desc2": "签到 2次 | 16-10-7 来过 武汉工程大学",
                        "card_display_type": 1,
                        "buttons": [],
                        "right_pannel": [],
                        "desc2_struct": "签到 2次 | 16-10-7 来过 武汉工程大学"
                    },
                    {
                        "card_type": 8,
                        "card_type_name": "",
                        "card_id": "renling4025789034821495",
                        "title": "",
                        "scheme": "https://m.weibo.cn/p/index?containerid=2310340006&count=10&needlocation=1&title=%25E4%25B8%258A%25E6%25B5%25B7&extparam=city%2C0021%2C5695741907&luicode=10000011&lfid=2302835695741907_-_INFO",
                        "display_arrow": 1,
                        "pic": "https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/wap180/4e704b16jw1esr3838rytj207h07hwf6.jpg",
                        "title_sub": "上海",
                        "desc1": "只能飞回去了明天直播[泪][泪]  ​",
                        "desc2": "签到 1次 | 16-10-1 来过 虹桥机场",
                        "card_display_type": 1,
                        "buttons": [],
                        "right_pannel": [],
                        "desc2_struct": "签到 1次 | 16-10-1 来过 虹桥机场"
                    },
                    {
                        "card_type": 8,
                        "card_type_name": "",
                        "card_id": "renling4025574223880677",
                        "title": "",
                        "scheme": "https://m.weibo.cn/p/index?containerid=2310340006&count=10&needlocation=1&title=%25E8%258B%258F%25E5%25B7%259E&extparam=city%2C0512%2C5695741907&luicode=10000011&lfid=2302835695741907_-_INFO",
                        "display_arrow": 1,
                        "pic": "https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/wap180/4e704b16jw1esr38i4ezrj20ab0abq44.jpg",
                        "title_sub": "苏州",
                        "desc1": "小弟开了4组抢票单,结果还是没抢到票,烦,只能上海飞回去了,去机场和在机场回来又远又麻烦,烦[泪][泪][泪]  ​",
                        "desc2": "签到 2次 | 16-10-1 来过 昆山市",
                        "card_display_type": 1,
                        "buttons": [],
                        "right_pannel": [],
                        "desc2_struct": "签到 2次 | 16-10-1 来过 昆山市"
                    }
                ],
                "display_arrow": 1,
                "is_asyn": 0,
                "buttontitle": "",
                "show_type": 0
            },
            {
                "card_type": 11,
                "itemid": "2306185695741907_-_likes",
                "is_asyn": 1,
                "card_group": [],
                "async_api": "/api/container/getItem?itemid=2306185695741907_-_likes&download="
            }
        ],
        "showAppTips": 0,
        "scheme": "sinaweibo://cardlist?containerid=2302835695741907_-_INFO&extparam=&luicode=10000011&lfid=2302835695741907&featurecode="
    }
}

就这样,我们获取到了完整的用户信息。
获取用户微博信息只需要拼接title为【主页】的【containerid】,剩下步骤同获取用户基本信息。

注意事项

需要注意的是,微博似乎对请求做了限制,如果你频繁发起请求可能会得到如下结果:


{
    "ok": 0,
    "msg": "这里还没有内容",
    "data": {
        "cards": []
    }
}

是不是很坑…o(╯□╰)o

转载原创文章请注明,转载自: LYLARES BLOG » 微博用户API分析

Not Comment Found