コード例 #1
0
  /**
   * 发布一条状态到人人网
   *
   * @param status 要发布的状态对象
   * @return 若状态为空或者发送失败,会抛出异常,否则返回成功 {@link FeedPublishResponseBean}对象
   * @throws RenrenException
   * @throws Throwable
   */
  public StatusSetResponseBean publish(StatusSetRequestParam status)
      throws RenrenException, Throwable {
    if (!renren.isSessionKeyValid()) {
      String errorMsg = "Session key is not valid.";
      throw new RenrenException(RenrenError.ERROR_CODE_TOKEN_ERROR, errorMsg, errorMsg);
    }

    // 参数不能为空
    if (status == null) {
      String errorMsg = "The parameter is null.";
      throw new RenrenException(RenrenError.ERROR_CODE_NULL_PARAMETER, errorMsg, errorMsg);
    }

    // 发布状态
    String response;
    try {
      Bundle params = status.getParams();
      response = renren.requestJSON(params);
    } catch (RenrenException rre) {
      Util.logger(rre.getMessage());
      throw rre;
    } catch (RuntimeException re) {
      Util.logger(re.getMessage());
      throw new Throwable(re);
    }

    RenrenError rrError = Util.parseRenrenError(response, Renren.RESPONSE_FORMAT_JSON);
    if (rrError != null) {
      throw new RenrenException(rrError);
    } else {
      try {
        JSONObject json = new JSONObject(response);
        if (json.optInt("result") == 1) {
          return new StatusSetResponseBean(response);
        } else {
          String errorMsg = "Cannot parse the response.";
          throw new RenrenException(
              RenrenError.ERROR_CODE_UNABLE_PARSE_RESPONSE, errorMsg, errorMsg);
        }
      } catch (JSONException je) {
        Util.logger(je.getMessage());
        throw new RenrenException(
            RenrenError.ERROR_CODE_UNABLE_PARSE_RESPONSE, je.getMessage(), je.getMessage());
      }
    }
  } // end of public Status publish(Activity activity, Status status,
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // 隐藏标题栏
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);

    // 使用父类的renren对象
    if (renren == null) {
      // renren对象获取失败,无法执行创建相册的操作,直接退出本Activity
      Util.logger("renren object is null, can't create album!");
      showTip("无法创建相册,请稍后重试!");

      finish();
    }
    renren.init(this);

    // 权限验证,如果用户已经登录并且权限满足,则初始化界面,否则结束Activity
    AuthorizationHelper.check(
        renren,
        CreateAlbumActivity.this,
        new String[] {PhotoHelper.CREATE_ALBUM_PERMISSION},
        new RenrenAuthListener() {

          @Override
          public void onRenrenAuthError(RenrenAuthError renrenAuthError) {
            finish();
          }

          @Override
          public void onComplete(Bundle values) {
            initComponents();
          }

          @Override
          public void onCancelLogin() {
            finish();
          }

          @Override
          public void onCancelAuth(Bundle values) {
            finish();
          }
        });
  }