コード例 #1
0
  private static OpenRequest getOpenRequest(
      StatusCallback callback, List<String> permissions, Activity activity) {
    OpenRequest req = new OpenRequest(activity);
    req.setCallback(callback);
    req.setPermissions(permissions);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);

    return req;
  }
コード例 #2
0
  public static void login(int cbIndex, String scope) {
    Log.i(TAG, "dsafsdfas");
    Session session = Session.getActiveSession();
    if (session == null) {
      session = new Session(mContext);
      Session.setActiveSession(session);
    }

    String[] permissions = null;
    mNeedPublishPermissions = false;
    if (scope != null) {
      permissions = scope.split(",");
      for (int i = 0; i < permissions.length; i++) {
        if (allPublishPermissions.contains(permissions[i])) {
          mNeedPublishPermissions = true;
          break;
        }
      }
    }

    if (session.isOpened()) {
      Log.i(TAG, "openActiveSession2");
      if (scope == null || session.getPermissions().containsAll(Arrays.asList(permissions))) {
        Log.e(TAG, "FB.login() called when user is already connected.");
      } else {
        mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
        mStatusCallback.mCallbackIndex = cbIndex;
        if (mNeedPublishPermissions) {
          session.requestNewPublishPermissions(
              new Session.NewPermissionsRequest(mActivity, Arrays.asList(permissions)));
        } else {
          session.requestNewReadPermissions(
              new Session.NewPermissionsRequest(mActivity, Arrays.asList(permissions)));
        }
      }
    } else {
      mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
      mStatusCallback.mCallbackIndex = cbIndex;
      Log.i(TAG, "openActiveSession1");
      if (!session.isClosed()) {
        mOpenRequest = new Session.OpenRequest(mActivity);
        if (permissions != null) mOpenRequest.setPermissions(Arrays.asList(permissions));
        mOpenRequest.setCallback(mStatusCallback);

        if (mNeedPublishPermissions) {
          Log.i(TAG, "openActiveSession4");
          session.openForPublish(mOpenRequest);
        } else {
          Log.i(TAG, "openActiveSession5");
          session.openForRead(mOpenRequest);
        }

      } else {
        Log.i(TAG, "openActiveSession");
        Session.openActiveSession(mActivity, true, mStatusCallback);
      }
    }

    /*
     * Session session = Session.getActiveSession(); if (!session.isOpened()
     * && !session.isClosed()) { session.openForRead(new
     * Session.OpenRequest(mActivity)
     * .setPermissions(Arrays.asList("basic_info")).setCallback(
     * mStatusCallback)); } else { Session.openActiveSession(mActivity,
     * true, mStatusCallback); }
     */
  }