use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class SDK method doLike.
/**
* 点赞
*
* @param statusId
* @param like
* @param cookie
* @return
* @throws TaskException
*/
public LikeResultBean doLike(String statusId, boolean like, String cookie) throws TaskException {
try {
String url = like ? "http://m.weibo.cn/attitudesDeal/add" : "http://m.weibo.cn/attitudesDeal/delete";
Map<String, String> cookieMap = new HashMap<String, String>();
String[] cookieValues = cookie.split(";");
for (String cookieValue : cookieValues) {
String key = cookieValue.split("=")[0];
String value = cookieValue.split("=")[1];
cookieMap.put(key, value);
}
// Logger.d(WeiboClientActivity.TAG, cookieMap);
Connection connection = Jsoup.connect(url);
connection.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0").referrer("http://m.weibo.cn/").cookies(cookieMap).data("id", statusId).method(Connection.Method.POST);
if (like)
connection.data("attitude", "heart");
String body = connection.execute().body();
if (!TextUtils.isEmpty(body)) {
Logger.d(TAG, body);
if (body.indexOf("http://passport.weibo.cn/sso/crossdomain") != -1)
throw new TaskException("-100", "未登录");
else if (body.indexOf("<html") != -1)
throw new TaskException("-100", "未登录");
LikeResultBean likeBean = JSON.parseObject(body, LikeResultBean.class);
if (likeBean.getOk() == 1) {
return likeBean;
} else if (likeBean.getOk() == -100) {
throw new TaskException("-100", "未登录");
} else {
throw new TaskException("", likeBean.getMsg());
}
}
} catch (Exception e) {
if (e instanceof TaskException)
throw (TaskException) e;
e.printStackTrace();
}
throw new TaskException(TaskException.TaskError.timeout.toString());
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class SinaSDK method webGetHotTopicsRecommendStatus.
/**
* 热门话题的推荐微博列表
*
* @param uid
* @param containerId
* @return
* @throws TaskException
*/
public StatusContents webGetHotTopicsRecommendStatus(String uid, String containerId, String sinceId) throws TaskException {
Params params = new Params();
params.addParameter("uid", uid);
params.addParameter("containerid", String.format("230530%s__default__mobile_info_-_pageapp:2305576d91c8d1eef00b0e5caac7d245bc1350", containerId));
if (!TextUtils.isEmpty(sinceId)) {
params.addParameter("since_id", sinceId);
}
Setting action = newSetting("webGetHotTopicsStatus", "container/getIndex", "热门话题推荐微博");
action.getExtras().put(HTTP_UTILITY, newSettingExtra(HTTP_UTILITY, TimelineHotTopicsHttpUtility.class.getName(), ""));
try {
return doGet(webConfig(), action, params, StatusContents.class);
} catch (Exception e) {
if (e instanceof TaskException)
checkWebResult((TaskException) e);
throw e;
}
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class SinaSDK method webGetHotTopics.
/**
* 热门话题
*
* @param sinceId
* @return
* @throws TaskException
*/
public WebHotTopicssBean webGetHotTopics(String containerId, String sinceId, int page) throws TaskException {
Params params = new Params();
params.addParameter("containerid", containerId);
if (!TextUtils.isEmpty(sinceId)) {
params.addParameter("since_id", sinceId);
} else if (page > 0) {
params.addParameter("page", String.valueOf(page));
}
Setting action = newSetting("webGetHotTopics", "container/getIndex", "热门话题");
action.getExtras().put(HTTP_UTILITY, newSettingExtra(HTTP_UTILITY, TopicHotHttpUtility.class.getName(), ""));
try {
return doGet(webConfig(), action, params, WebHotTopicssBean.class);
} catch (Exception e) {
if (e instanceof TaskException)
checkWebResult((TaskException) e);
throw e;
}
}
use of org.aisen.android.network.task.TaskException 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;
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class SinaSDK method webCommentLike.
/**
* 评论点赞
*
* @param comment
* @param like
* @return
* @throws TaskException
*/
public LikeResultBean webCommentLike(StatusComment comment, boolean like) throws TaskException {
Params params = new Params();
params.addParameter("id", comment.getLikeId());
params.addParameter("st", "380e9f");
Setting action = newSetting("webCommentLike", like ? "comment/like" : "comment/dislike", "评论点赞");
HttpConfig config = webConfig();
config.addHeader("Referer", String.format("http://m.weibo.cn/status/%s", comment.getStatusId()));
config.addHeader("Content-Type", "application/x-www-form-urlencoded");
config.addHeader("Host", "m.weibo.cn");
config.addHeader("Accept-Language", "zh-CN,en-US;q=0.8");
config.addHeader("Accept", "application/json, text/plain, */*");
String body = doPost(config, action, null, params, null, String.class);
if (!TextUtils.isEmpty(body)) {
Logger.d(TAG, body);
if (body.indexOf("http://passport.weibo.cn/sso/crossdomain") != -1)
throw new TaskException("-100", "未登录");
else if (body.indexOf("<html") != -1)
throw new TaskException("-100", "未登录");
LikeResultBean likeBean = JSON.parseObject(body, LikeResultBean.class);
if (likeBean.getOk() == 1) {
return likeBean;
} else if (likeBean.getOk() == -100) {
throw new TaskException("-100", "未登录");
} else {
throw new TaskException("", likeBean.getMsg());
}
}
throw new TaskException("-100", "未登录");
}
Aggregations