private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    String accessToken = "";
    if ((exception instanceof FacebookOperationCanceledException
        || exception instanceof FacebookAuthorizationException)) {
      setResultAndClose(false);
    } else if (state == SessionState.OPENED_TOKEN_UPDATED) {
      accessToken = session.getAccessToken();
      FacebookHelper.saveAccessToken(activity, accessToken);
      try {
        linked = FacebookUtils.isLinkedForWrite(activity, FacebookConstants.PUBLISH_PERMISSIONS);
      } catch (Exception e) {
      }
      if (!linked) {
        FacebookUtils.linkForWrite(
            activity,
            FacebookHelper.getAccessToken(activity),
            false,
            new SocializeAuthListener() {

              @Override
              public void onError(SocializeException error) {
                // TODO Auto-generated method stub
                setResultAndClose(false);
              }

              @Override
              public void onCancel() {
                // TODO Auto-generated method stub
                setResultAndClose(false);
              }

              @Override
              public void onAuthSuccess(SocializeSession session) {

                setResultAndClose(true);
              }

              @Override
              public void onAuthFail(SocializeException error) {
                // TODO Auto-generated method stub
                setResultAndClose(false);
              }
            },
            FacebookConstants
                .PUBLISH_PERMISSIONS); // getNexerciseApplication().getSocializeAuthListener());
      } else {
        setResultAndClose(true);
      }
    }
  }
コード例 #2
0
  @Override
  public void onResume(final Activity context) {

    if (!Socialize.getSocialize().isInitialized(context)) {
      Socialize.getSocialize()
          .initAsync(
              context,
              new SocializeInitListener() {
                @Override
                public void onError(SocializeException error) {
                  SocializeLogger.e("Error occurred on resume", error);
                }

                @Override
                public void onInit(Context ctx, IOCContainer container) {
                  // This is the current context
                  setContext(ctx);

                  if (FacebookUtils.isAvailable(ctx)) {
                    try {
                      FacebookUtils.extendAccessToken(context, null);
                    } catch (Exception e) {
                      SocializeLogger.e("Error occurred on resume", e);
                    }
                  }
                }
              });
    } else {
      if (paused && FacebookUtils.isAvailable(context)) {
        try {
          FacebookUtils.extendAccessToken(context, null);
        } catch (Exception e) {
          SocializeLogger.e("Error occurred on resume", e);
        }
        paused = false;
      }

      // This is the current context
      setContext(context);
    }
  }