Search in sources :

Example 6 with Setting

use of org.aisen.android.common.setting.Setting in project AisenWeiBo by wangdan.

the class SinaSDK method searchsResultUsers.

/**
	 * 使用H5页面查询用户
	 *
	 * @param q
	 * @param cookies
	 * @return
	 * @throws TaskException
	 */
public ArrayList<SearchsResultUser> searchsResultUsers(String q, String cookies) throws TaskException {
    ArrayList<SearchsResultUser> resultUsers = new ArrayList<>();
    Setting action = newSetting("searchsResultUsers", "page/pageJson", "获取用户");
    action.getExtras().put(BASE_URL, newSettingExtra(BASE_URL, "http://m.weibo.cn/", ""));
    Params params = new Params();
    //		params.addParameter("containerid", "100103");
    //		params.addParameter("type", "3");
    //		params.addParameter("page", "1");
    //		params.addParameter("q", q);
    // 我也搞不懂这个脑残接口到底怎么玩的
    // http://m.weibo.cn/page/pageJson?containerid=100103type%3D3%26q%3Dwang&page=1
    params.addParameter("containerid", "100103type%3D3%26q%3D" + q + "&page=1");
    try {
        HttpConfig config = getHttpConfig();
        //			config.cookie = cookies;
        //			config.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        //			config.addHeader("Referer", "http://m.weibo.cn/searchs");
        String response = doGet(config, action, params, String.class);
        JSONObject responseJSON = JSONObject.parseObject(response);
        int ok = responseJSON.getInteger("ok");
        if (ok == 1) {
            JSONArray cardsArray = responseJSON.getJSONArray("cards");
            if (cardsArray.size() > 0) {
                JSONObject cardGroupsObject = cardsArray.getJSONObject(1);
                JSONArray cardGroupArray = cardGroupsObject.getJSONArray("card_group");
                for (int i = 0; i < cardGroupArray.size(); i++) {
                    JSONObject cardGroup = cardGroupArray.getJSONObject(i);
                    SearchsResultUser user = new SearchsResultUser();
                    user.setDesc1(cardGroup.getString("desc1"));
                    user.setDesc2(cardGroup.getString("desc2"));
                    JSONObject userJSON = cardGroup.getJSONObject("user");
                    user.setId(userJSON.getString("id"));
                    user.setFollowing(userJSON.getBoolean("following"));
                    user.setFollow_me(userJSON.getBoolean("follow_me"));
                    user.setFansNum(userJSON.getString("fansNum"));
                    user.setScreen_name(userJSON.getString("screen_name"));
                    user.setDescription(userJSON.getString("description"));
                    user.setProfile_image_url(userJSON.getString("profile_image_url"));
                    user.setStatuses_count(userJSON.getInteger("statuses_count"));
                    user.setGender(userJSON.getString("gender"));
                    user.setRemark(userJSON.getString("remark"));
                    resultUsers.add(user);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof TaskException) {
            throw e;
        }
    }
    return resultUsers;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) TaskException(org.aisen.android.network.task.TaskException) SearchsResultUser(org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser) Setting(org.aisen.android.common.setting.Setting) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) Params(org.aisen.android.network.http.Params) HttpConfig(org.aisen.android.network.http.HttpConfig) ParseException(java.text.ParseException) TaskException(org.aisen.android.network.task.TaskException)

Aggregations

Setting (org.aisen.android.common.setting.Setting)6 Params (org.aisen.android.network.http.Params)6 TaskException (org.aisen.android.network.task.TaskException)4 JSONArray (com.alibaba.fastjson.JSONArray)3 JSONObject (com.alibaba.fastjson.JSONObject)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)2 HttpConfig (org.aisen.android.network.http.HttpConfig)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 PicUrls (org.aisen.weibo.sina.sinasdk.bean.PicUrls)1 SearchsResultUser (org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser)1 StatusContent (org.aisen.weibo.sina.sinasdk.bean.StatusContent)1 WallpaperBeans (org.aisen.weibo.sina.support.bean.WallpaperBeans)1