コード例 #1
0
    @Override
    public TokenInfo workInBackground(AccountBean... params) throws TaskException {
      Logger.w("run CheckAccountValidTask");

      TokenInfo token = null;
      TokenInfo adToken = null;

      try {
        AccountBean account = params[0];
        // Aisen授权
        try {
          token =
              SinaSDK.getInstance(account.getAccessToken())
                  .getTokenInfo(account.getAccessToken().getToken());
        } catch (TaskException e) {
          e.printStackTrace();
          if ("21327".equals(e.getCode()) || "21317".equals(e.getCode())) {
            token = new TokenInfo();
            token.setExpire_in(0);
          }
        }
        if (token != null) account.getAccessToken().setExpires_in(token.getExpire_in());
        // Weico授权
        try {
          if (account.getAdvancedToken() != null)
            adToken =
                SinaSDK.getInstance(account.getAdvancedToken())
                    .getTokenInfo(account.getAdvancedToken().getToken());
          else {
            adToken = new TokenInfo();
            adToken.setExpire_in(0);
          }
        } catch (TaskException e) {
          e.printStackTrace();
          if ("21327".equals(e.getCode()) || "21317".equals(e.getCode())) {
            adToken = new TokenInfo();
            adToken.setExpire_in(0);
          }
        }
        if (account.getAdvancedToken() != null && adToken != null)
          account.getAdvancedToken().setExpires_in(adToken.getExpire_in());
      } catch (Throwable e) {
      }

      if (token != null) {
        token.setUid(params[0].getUid());
      }
      return token;
    }
コード例 #2
0
    @Override
    protected void onSuccess(TokenInfo tokenInfo) {
      super.onSuccess(tokenInfo);

      // 同一登录账户
      if (tokenInfo != null
          && AppContext.isLoggedIn()
          && AppContext.getAccount().getUid().equals(tokenInfo.getUid())) {
        if (BaseActivity.getRunningActivity() != null
            && BaseActivity.getRunningActivity() instanceof MainActivity) {
          if (getParams()[0].getAccessToken().isExpired())
            requestLogin(BaseActivity.getRunningActivity(), getParams()[0]);
        }
      }
    }