Пример #1
0
  private void composeNewPost() {
    StatusesAPI api = new StatusesAPI(mAccessToken);
    mContent = mEdit.getText().toString();
    if (TextUtils.isEmpty(mContent)) return;

    if (!TextUtils.isEmpty(mPicPath)) {
      Util.showToast(this, R.string.sending);
      api.upload(this.mContent, this.mPicPath, mLatitude, mLongitude, this);
    } else {
      // Just update a text weibo!
      api.update(mContent, mLatitude, mLongitude, this);
    }
  }
Пример #2
0
  public static String WeiboStatusUpdate(
      Context context, final String content, final RequestListener requestListener) {

    weiboUpdateResult = "success";
    if (accessToken == null) {
      WeiboParameters parameters = new WeiboParameters();
      parameters.add("forcelogin", "true");
      com.weibo.sdk.android.util.Utility.isWifi(context);
      weibo.startDialog(
          context,
          parameters,
          new WeiboAuthListener() {
            // weibo.authorize(context, new WeiboAuthListener() {
            @Override
            public void onComplete(Bundle bundle) {
              access_token = bundle.getString("access_token");
              expires_in = bundle.getString("expires_in");
              accessToken = new Oauth2AccessToken(access_token, expires_in);
              try {
                SendToken();
              } catch (IOException e) {
                e.printStackTrace();
              }

              StatusesAPI statusesAPI = new StatusesAPI(accessToken);
              if (requestListener != null) {
                statusesAPI.update(content, null, null, requestListener);
              } else {
                statusesAPI.update(
                    content,
                    null,
                    null,
                    new RequestListener() {
                      @Override
                      public void onComplete(String s) {
                        weiboUpdateResult = s;
                        weiboUpdateResult = "success";
                        // Toast.makeText(Record_Journal.this, "微博发布成功", Toast.LENGTH_SHORT).show();
                      }

                      @Override
                      public void onIOException(IOException e) {
                        weiboUpdateResult = e.getMessage();
                        weiboUpdateResult = "fail";
                        // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                        // Toast.LENGTH_SHORT).show();
                      }

                      @Override
                      public void onError(WeiboException e) {
                        weiboUpdateResult = e.getMessage();
                        weiboUpdateResult = "fail";
                        // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                        // Toast.LENGTH_SHORT).show();
                      }
                    });
              }
            }

            @Override
            public void onWeiboException(WeiboException e) {
              weiboUpdateResult = e.getMessage();
              weiboUpdateResult = "fail";

              clearToken();
            }

            @Override
            public void onError(WeiboDialogError weiboDialogError) {
              weiboUpdateResult = weiboDialogError.getMessage();
              weiboUpdateResult = "fail";

              clearToken();
            }

            @Override
            public void onCancel() {
              clearToken();
            }
          });
    } else {
      StatusesAPI statusesAPI = new StatusesAPI(accessToken);
      if (requestListener != null) {
        statusesAPI.update(content, null, null, requestListener);
      } else {
        statusesAPI.update(
            content,
            null,
            null,
            new RequestListener() {
              @Override
              public void onComplete(String s) {
                weiboUpdateResult = s;
                weiboUpdateResult = "success";
                // Toast.makeText(Record_Journal.this, "微博发布成功", Toast.LENGTH_SHORT).show();
              }

              @Override
              public void onIOException(IOException e) {
                weiboUpdateResult = e.getMessage();
                weiboUpdateResult = "fail";
                // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                // Toast.LENGTH_SHORT).show();
              }

              @Override
              public void onError(WeiboException e) {
                weiboUpdateResult = e.getMessage();
                weiboUpdateResult = "fail";
                // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                // Toast.LENGTH_SHORT).show();
              }
            });
      }
    }

    return weiboUpdateResult;
  }