예제 #1
0
  private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
      // Check for publish permissions
      List<String> permissions = session.getPermissions();
      if (!isSubsetOf(PERMISSIONS, permissions)) {
        Session.NewPermissionsRequest newPermissionsRequest =
            new Session.NewPermissionsRequest(this, PERMISSIONS);
        session.requestNewPublishPermissions(newPermissionsRequest);
      }

      makeMeRequest(session);

      // bLoginFacebook.setText(R.string.Log_Out);
      bLoginFacebook.setOnClickListener(
          new OnClickListener() {
            public void onClick(View view) {
              onClickLogout();
            }
          });
    } else {
      // bLoginFacebook.setText(R.string.Log_In);
      bLoginFacebook.setOnClickListener(
          new OnClickListener() {
            public void onClick(View view) {
              onClickLogin();
            }
          });
    }
  }
  private void getPermissions(CallbackContext callbackContext) throws JSONException {
    Session session = getSession();

    if (!session.getState().isOpened()) {
      callbackContext.success("login_required");
      return;
    }
    Log.d(TAG, "Permissions: " + Arrays.toString(session.getPermissions().toArray()));
    JSONObject response = new JSONObject();

    for (String permission : session.getPermissions()) {
      response.put(permission, 1);
    }

    callbackContext.success(response);
  }
예제 #3
0
 /**
  * Gets the permissions associated with the current session or null if no session has been
  * created.
  *
  * @return the permissions associated with the current session
  */
 protected final List<String> getSessionPermissions() {
   if (sessionTracker != null) {
     Session currentSession = sessionTracker.getSession();
     return (currentSession != null) ? currentSession.getPermissions() : null;
   }
   return null;
 }
  public static void login(String params, final Activity activity) {
    Session session = Session.getActiveSession();
    if (session == null) {
      Log.w(FB.TAG, "Session not found. Call init() before calling login()");
      return;
    }
    // if the old session is closed (or login was cancelled), create new one
    if (session.isClosed()) {
      session =
          new Builder(FB.getUnityActivity()).setApplicationId(session.getApplicationId()).build();
      Session.setActiveSession(session);
    }
    final UnityMessage unityMessage = new UnityMessage("OnLoginComplete");

    unityMessage.put("key_hash", FB.getKeyHash());

    // parse and separate the permissions into read and publish permissions
    List<String> permissions = new ArrayList<String>();
    UnityParams unity_params = UnityParams.parse(params, "couldn't parse login params: " + params);
    if (unity_params.hasString("scope")) {
      permissions =
          new ArrayList<String>(Arrays.asList(unity_params.getString("scope").split(",")));
    }
    List<String> publishPermissions = new ArrayList<String>();
    List<String> readPermissions = new ArrayList<String>();
    if (permissions.size() > 0) {
      for (String s : permissions) {
        if (s.length() == 0) {
          continue;
        }
        if (Session.isPublishPermission(s)) {
          publishPermissions.add(s);
        } else {
          readPermissions.add((s));
        }
      }
    }
    boolean hasPublishPermissions = !publishPermissions.isEmpty();

    // check to see if the readPermissions have been TOSed already
    // we don't need to show the readPermissions dialog if they have all been TOSed even though it's
    // a mix
    // of permissions
    boolean showMixedPermissionsFlow =
        hasPublishPermissions && !session.getPermissions().containsAll(readPermissions);

    // if we're logging in and showing a mix of publish and read permission, we need to split up the
    // dialogs
    // first just show the read permissions, after they are accepted show publish permissions
    if (showMixedPermissionsFlow) {
      Session.StatusCallback afterReadPermissionCallback =
          getAfterReadPermissionLoginCallback(unityMessage, publishPermissions, activity);
      sessionOpenRequest(session, afterReadPermissionCallback, activity, readPermissions, false);
    } else {
      Session.StatusCallback finalCallback = getFinalCallback(unityMessage, activity);
      sessionOpenRequest(session, finalCallback, activity, permissions, hasPublishPermissions);
    }
  }
예제 #5
0
 public boolean checkPermissions() {
   Session session = Session.getActiveSession();
   List<String> permissions = session.getPermissions();
   if (!isSubsetOf(FacebookHelper.PERMISSIONS, permissions)) {
     Session.NewPermissionsRequest newPermissionsRequest =
         new Session.NewPermissionsRequest(activity, FacebookHelper.PERMISSIONS);
     session.requestNewPublishPermissions(newPermissionsRequest);
     return false;
   }
   return true;
 }
 private void onSessionStateChange(Session session, SessionState state, Exception exception) {
   if (state.isOpened()) {
     Log.i(TAG, "Logged in...");
     // Check for publish permissions
     List<String> permissions = session.getPermissions();
     if (!isSubsetOf(PERMISSIONS, permissions)) {
       Session.NewPermissionsRequest newPermissionsRequest =
           new Session.NewPermissionsRequest(this, PERMISSIONS);
       session.requestNewPublishPermissions(newPermissionsRequest);
       return;
     }
   } else if (state.isClosed()) {
     Log.i(TAG, "Logged out...");
   }
 }
 private boolean validatePermissions(
     List<String> permissions, SessionAuthorizationType authType, Session currentSession) {
   if (SessionAuthorizationType.PUBLISH.equals(authType)) {
     if (Utility.isNullOrEmpty(permissions)) {
       throw new IllegalArgumentException(
           "Permissions for publish actions cannot be null or empty.");
     }
   }
   if (currentSession != null && currentSession.isOpened()) {
     if (!Utility.isSubset(permissions, currentSession.getPermissions())) {
       Log.e(TAG, "Cannot set additional permissions when session is already open.");
       return false;
     }
   }
   return true;
 }
예제 #8
0
  public static void restoreSession(Activity activity, Bundle savedInstanceState) {
    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
      if (savedInstanceState != null) {
        session = Session.restoreSession(activity, null, statusCallback, savedInstanceState);
      } else {
        String accessTokenString =
            SharedPreferenceUtil.getValue(SharedPreferenceUtil.PREF_FACEBOOK_TOKEN, null);
        String expireDateString =
            SharedPreferenceUtil.getValue(SharedPreferenceUtil.PREF_FACEBOOK_EXPIRE_DATE, null);
        if (accessTokenString != null) {
          try {
            Date expireDate = dateFormat.parse(expireDateString);
            AccessToken accessToken =
                AccessToken.createFromExistingAccessToken(
                    accessTokenString,
                    expireDate,
                    new Date(),
                    AccessTokenSource.FACEBOOK_APPLICATION_NATIVE,
                    PERMISSIONS);
            Session.openActiveSessionWithAccessToken(activity, accessToken, statusCallback);
          } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }

      if (session != null && session.isOpened()) {
        List<String> permissions = session.getPermissions();
        if (!permissions.containsAll(PERMISSIONS)) {
          requestPublishPermissions(activity, session);
        }
      }
    }
  }
예제 #9
0
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    CheckBluetoothConenct = false;
    Threadrun = true;
    if (haveInternet()) {
      Session s = Session.getActiveSession();
      if (s.isOpened()) {
        try {
          if (s != null) {

            // Check for publish permissions
            List<String> permissions = s.getPermissions();

            if (!isSubsetOf(PERMISSIONS, permissions)) {
              pendingPublishReauthorization = true;
              Session.NewPermissionsRequest newPermissionsRequest =
                  new Session.NewPermissionsRequest(this, PERMISSIONS);
              s.requestNewPublishPermissions(newPermissionsRequest);
              return;
            }
          }
          Initial();
          if (getGPSService) {
            // 服務提供者、更新頻率毫秒、最短距離、地點改變時呼叫物件
            lms.requestLocationUpdates(bestProvider, 60000, 1, (LocationListener) this);
          }
        } catch (Exception e) {
          System.out.println(e.toString());
        }
      }
    } else {
      NoInternetDialog();
    }
  }
예제 #10
0
 private boolean hasPublishPermission() {
   Session session = Session.getActiveSession();
   return session != null && session.getPermissions().contains("publish_actions");
 }
  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); }
     */
  }