Пример #1
0
  public void loadComments() {
    CommentsAPI commentsAPI = new CommentsAPI(BaseActivity.token);
    commentsAPI.show(
        status.getId(),
        0,
        0,
        20,
        1,
        WeiboAPI.AUTHOR_FILTER.ALL,
        new RequestListener() {
          @Override
          public void onComplete(String response) {
            JSONTokener tokener = new JSONTokener(response);
            try {
              JSONArray jsonArray = ((JSONObject) tokener.nextValue()).getJSONArray("comments");
              List<Comment> comments = new ArrayList<Comment>();
              for (int i = 0; i < jsonArray.length(); ++i) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                comments.add(JSONParser.parseComment(jsonObject));
              }

              Message message = new Message();
              message.obj = comments;
              message.what = UPDATE_CMT;
              handler.sendMessage(message);

            } catch (JSONException e) {
              e.printStackTrace();
            }
          }

          @Override
          public void onIOException(IOException e) {}

          @Override
          public void onError(WeiboException e) {}
        });
  }
  @Override
  public void onClick(View v) {
    if (v.equals(btnFav)) {
      Util.showToast(BlogFunActivity.this, "api访问请求已执行,请等待结果");
      FavoritesAPI fav = new FavoritesAPI(MainActivity.accessToken);
      fav.create(
          blogId,
          new RequestListener() {
            @Override
            public void onIOException(IOException e) {
              e.printStackTrace();
            }

            @Override
            public void onError(WeiboException e) {
              Util.showToast(BlogFunActivity.this, "收藏失败:" + e.getMessage());
            }

            @Override
            public void onComplete(String response) {
              //                    Util.showToast(BlogFunActivity.this,response);
              if (mTv != null) {
                Util.setTextViewContent(BlogFunActivity.this, mTv, "收藏结果:" + response);
              }
            }
          });
    } else if (v.equals(btnForward)) {
      Util.showToast(BlogFunActivity.this, "api访问请求已执行,请等待结果");
      StatusesAPI status = new StatusesAPI(MainActivity.accessToken);
      status.repost(
          blogId,
          "无" + System.currentTimeMillis(),
          WeiboAPI.COMMENTS_TYPE.NONE,
          new RequestListener() {

            @Override
            public void onIOException(IOException e) {
              e.printStackTrace();
            }

            @Override
            public void onError(WeiboException e) {
              Util.showToast(BlogFunActivity.this, "转发失败:" + e.getMessage());
            }

            @Override
            public void onComplete(String response) {
              //                            Util.showToast(BlogFunActivity.this,response);
              if (mTv != null) {
                Util.setTextViewContent(BlogFunActivity.this, mTv, "转发结果:" + response);
              }
            }
          });
    } else if (v.equals(btnComment)) {
      Util.showToast(BlogFunActivity.this, "api访问请求已执行,请等待结果");
      CommentsAPI comment = new CommentsAPI(MainActivity.accessToken);
      comment.create(
          "顶!" + System.currentTimeMillis(),
          blogId,
          false,
          new RequestListener() {
            @Override
            public void onIOException(IOException e) {
              e.printStackTrace();
            }

            @Override
            public void onError(WeiboException e) {
              Util.showToast(BlogFunActivity.this, "评论失败:" + e.getMessage());
            }

            @Override
            public void onComplete(String response) {
              //                    Util.showToast(BlogFunActivity.this,response);
              if (mTv != null) {
                Util.setTextViewContent(BlogFunActivity.this, mTv, "评论结果:" + response);
              }
            }
          });
    }
  }