java类com.facebook.Session的实例源码

FacebookFragment.java 文件源码 项目:AndroidBackendlessChat 阅读 25 收藏 0 点赞 0 评论 0
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
FriendPickerFragment.java 文件源码 项目:AndroidBackendlessChat 阅读 29 收藏 0 点赞 0 评论 0
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
BFacebookManager.java 文件源码 项目:AndroidBackendlessChat 阅读 22 收藏 0 点赞 0 评论 0
public static  Promise<List<GraphUser>, BError, Void>  getUserFriendList(){

        final Deferred<List<GraphUser>, BError, Void> deferred = new DeferredObject<>();


        if (!Session.getActiveSession().getState().isOpened())
        {
            return deferred.reject(new BError(BError.Code.SESSION_CLOSED));
        }
        Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                deferred.resolve(users);
            }
        });

        req.executeAsync();

        return deferred.promise();
    }
BFacebookManager.java 文件源码 项目:AndroidBackendlessChat 阅读 23 收藏 0 点赞 0 评论 0
public static void logout(Context ctx){
    userFacebookAccessToken = null;

    if (Session.getActiveSession() != null)
    {
        Session.getActiveSession().closeAndClearTokenInformation();
    }
    else
    {
        if (DEBUG) Timber.e("getActiveSessionIsNull");
        Session session = Session.openActiveSessionFromCache(ctx);

        if (session != null)
            session.closeAndClearTokenInformation();
    }
}
FacebookFragment.java 文件源码 项目:chat-sdk-android-push-firebase 阅读 24 收藏 0 点赞 0 评论 0
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
FriendPickerFragment.java 文件源码 项目:chat-sdk-android-push-firebase 阅读 34 收藏 0 点赞 0 评论 0
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
BFacebookManager.java 文件源码 项目:chat-sdk-android-push-firebase 阅读 24 收藏 0 点赞 0 评论 0
public static  Promise<List<GraphUser>, BError, Void>  getUserFriendList(){

        final Deferred<List<GraphUser>, BError, Void> deferred = new DeferredObject<>();


        if (!Session.getActiveSession().getState().isOpened())
        {
            return deferred.reject(new BError(BError.Code.SESSION_CLOSED));
        }
        Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                deferred.resolve(users);
            }
        });

        req.executeAsync();

        return deferred.promise();
    }
BFacebookManager.java 文件源码 项目:chat-sdk-android-push-firebase 阅读 22 收藏 0 点赞 0 评论 0
public static void logout(Context ctx){
    userFacebookAccessToken = null;

    if (Session.getActiveSession() != null)
    {
        Session.getActiveSession().closeAndClearTokenInformation();
    }
    else
    {
        if (DEBUG) Timber.e("getActiveSessionIsNull");
        Session session = Session.openActiveSessionFromCache(ctx);

        if (session != null)
            session.closeAndClearTokenInformation();
    }
}
FragmentSocialTimeline.java 文件源码 项目:aptoide-client 阅读 24 收藏 0 点赞 0 评论 0
private void startLogin(GraphUser user, Session session) {
    try {
        loginMode = true;
        Fragment fragment = new FragmentSignIn();
        Bundle args = new Bundle();
        args.putInt(FragmentSignIn.LOGIN_MODE_ARG, LoginActivity.Mode.FACEBOOK.ordinal());
        args.putString(FragmentSignIn.LOGIN_PASSWORD_OR_TOKEN_ARG, session.getAccessToken());
        args.putString(FragmentSignIn.LOGIN_USERNAME_ARG, (String) user.getProperty("email"));
        fragment.setArguments(args);
        getChildFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, "tag").setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();

        Analytics.SocialTimeline.login();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
FbLoginDelegate.java 文件源码 项目:pedefacil 阅读 23 收藏 0 点赞 0 评论 0
public void requestUserData( Session session ) {
    // Request user data and show the results
    Request.newMeRequest(session, new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (user != null) {
               User currentUser = new User();
                currentUser.setUserId(user.getId());
                currentUser.setUserName(user.getUsername());
                currentUser.setFirstName(user.getFirstName());
                currentUser.setLastName(user.getLastName());
                currentUser.setDisplayName(user.getName());
                currentUser.setMail((String) user.getProperty("email"));
                currentUser.setProviderDisplayName("Facebook");
                currentUser.setProvider(PROVIDER_NAME);
               FbLoginDelegate.this.mUserHelper.setCurrentUser(currentUser);
                if ( mUserSessionCallback != null) {
                    mUserSessionCallback.onLogin();
                }
            }
        }
    }).executeAsync();
}
FacebookFragment.java 文件源码 项目:TP-Formation-Android 阅读 27 收藏 0 点赞 0 评论 0
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
LoginFragment.java 文件源码 项目:house-devs 阅读 45 收藏 0 点赞 0 评论 0
/**
 * Changes the UI when an interaction with the Session object occurs with the user.
 * @param session       The current active Session.
 * @param sessionState  The current state of the active Session.
 * @param e             An Exception if there is one.
 */
private void onSessionStateChange(Session session, SessionState sessionState, Exception e) {
    if (sessionState == SessionState.OPENED) {
        Log.d(TAG, "Successful login!");
        new Request(session, "/me", null, HttpMethod.GET, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                JSONObject obj = response.getGraphObject().getInnerJSONObject();
                Log.d(TAG, "Got back " + obj + " from Facebook API.");
                UserSession.getInstance().setFacebookData(obj);
                getUserData();
            }
        }).executeAsync();
    } else if (e != null) { // handle exception

    }
}
FacebookFragment.java 文件源码 项目:BrainStudio 阅读 25 收藏 0 点赞 0 评论 0
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
FbLoginActivity.java 文件源码 项目:CallService-Facebook-sample 阅读 28 收藏 0 点赞 0 评论 0
private boolean ensureOpenSession() {
    if (Session.getActiveSession() == null
            || !Session.getActiveSession().isOpened()) {
        Session.openActiveSession(this, true, PERMISSIONS,
                new Session.StatusCallback() {
                    @Override
                    public void call(Session session, SessionState state,
                                     Exception exception) {
                        onSessionStateChanged(session, state, exception);
                    }
                });
        return false;
    }
    makeMeRequest();
    return true;
}
FacebookFragment.java 文件源码 项目:snake-game-aws 阅读 32 收藏 0 点赞 0 评论 0
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
Left_Menu.java 文件源码 项目:IPRJapp 阅读 109 收藏 0 点赞 0 评论 0
private void sendRequestDialog() {

      Bundle params = new Bundle();
      params.putString("title", "Solicitação de Aplicativo");
      params.putString("message", "Experimente o IPRJapp");
      params.putString("link","https://play.google.com/store/apps/details?id=com.wb.goog.batman.brawler2013");
      params.putString("data",
          "{\"badge_of_awesomeness\":\"1\"," +
          "\"social_karma\":\"5\"}");  

      WebDialog requestsDialog = (
          new WebDialog.RequestsDialogBuilder(this.getActivity(), Session.getActiveSession(), params))
              .setOnCompleteListener(new OnCompleteListener() {

                  @Override
                  public void onComplete(Bundle values, FacebookException error) {
                  }

              })
              .build();
      requestsDialog.show();
  }
FacebookLoginActivity.java 文件源码 项目:UniversalSocialLoginAndroid 阅读 25 收藏 0 点赞 0 评论 0
private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
        makeMeRequest();
        // textInstructionsOrLink.setText(URL_PREFIX_FRIENDS +
        // session.getAccessToken());

        // buttonLoginLogout.setText("Logout");
        // buttonLoginLogout.setOnClickListener(new OnClickListener() {
        // public void onClick(View view) { onClickLogout(); }
        // });
    } else {
        onClickLogin();
        // textInstructionsOrLink.setText("Please login");
        // buttonLoginLogout.setText("Login");
        // buttonLoginLogout.setOnClickListener(new OnClickListener() {
        // public void onClick(View view) { onClickLogin(); }
        // });
    }

}
FacebookProfileConnector.java 文件源码 项目:guitar_guy 阅读 25 收藏 0 点赞 0 评论 0
@Override
public void connect(Activity activity)
{
    Session session = Session.getActiveSession();

    // TODO: I think we should validate the session here, but to what
    // extent?

    MadFacebookStatusCallback statusCallback =
            new MadFacebookStatusCallback();

    // Check if the session is already open.
    if (!session.isOpened() && !session.isClosed())
    {
        OpenRequest openRequest = new OpenRequest(activity);
        session.openForRead(openRequest
                .setCallback(statusCallback));
    }
    else
    {
        Session.openActiveSession(activity, true,
                statusCallback);
    }

}
UserHome.java 文件源码 项目:CallService-Facebook-sample 阅读 31 收藏 0 点赞 0 评论 0
public void populateContact() {
    final Session session = Session.getActiveSession();
    new Request(session, "/me/friends", null, HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {

                    // Process the returned response
                    GraphObject graphObject = response.getGraphObject();
                    if (graphObject != null) {
                        // Check if there is extra data
                        if (graphObject.getProperty("data") != null) {
                                JSONArray arrayObject = (JSONArray) graphObject
                                        .getProperty("data");

                                int count = arrayObject.length();
                                if(count == 0)
                                    hasAppFriends = false;
                                // Ensure the user has at least one friend
                                //session.close();
                        }
                    }
                }

            }).executeAsync();
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Constructs a SessionTracker to track the Session object passed in.
 * If the Session is null, then it will track the active Session instead.
 * 
 * @param context the context object.
 * @param callback the callback to use whenever the Session's state changes
 * @param session the Session object to track
 * @param startTracking whether to start tracking the Session right away
 */
public SessionTracker(Context context, Session.StatusCallback callback, Session session, boolean startTracking) {
    this.callback = new CallbackWrapper(callback);
    this.session = session;
    this.receiver = new ActiveSessionBroadcastReceiver();
    this.broadcastManager = LocalBroadcastManager.getInstance(context);

    if (startTracking) {
        startTracking();
    }
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Set the Session object to track.
 * 
 * @param newSession the new Session object to track
 */
public void setSession(Session newSession) {
    if (newSession == null) {
        if (session != null) {
            // We're current tracking a Session. Remove the callback
            // and start tracking the active Session.
            session.removeCallback(callback);
            session = null;
            addBroadcastReceiver();
            if (getSession() != null) {
                getSession().addCallback(callback);
            }
        }
    } else {
        if (session == null) {
            // We're currently tracking the active Session, but will be
            // switching to tracking a different Session object.
            Session activeSession = Session.getActiveSession();
            if (activeSession != null) {
                activeSession.removeCallback(callback);
            }
            broadcastManager.unregisterReceiver(receiver);
        } else {
            // We're currently tracking a Session, but are now switching 
            // to a new Session, so we remove the callback from the old 
            // Session, and add it to the new one.
            session.removeCallback(callback);
        }
        session = newSession;
        session.addCallback(callback);
    }
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Stop tracking the Session and remove any callbacks attached
 * to those sessions.
 */
public void stopTracking() {
    if (!isTracking) {
        return;
    }
    Session session = getSession();
    if (session != null) {
        session.removeCallback(callback);
    }
    broadcastManager.unregisterReceiver(receiver);
    isTracking = false;
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 24 收藏 0 点赞 0 评论 0
private void addBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Session.ACTION_ACTIVE_SESSION_SET);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_UNSET);

    // Add a broadcast receiver to listen to when the active Session
    // is set or unset, and add/remove our callback as appropriate    
    broadcastManager.registerReceiver(receiver, filter);
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void onReceive(Context context, Intent intent) {
    if (Session.ACTION_ACTIVE_SESSION_SET.equals(intent.getAction())) {
        Session session = Session.getActiveSession();
        if (session != null) {
            session.addCallback(SessionTracker.this.callback);
        }
    }
}
SessionTracker.java 文件源码 项目:AndroidBackendlessChat 阅读 27 收藏 0 点赞 0 评论 0
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
FacebookFragment.java 文件源码 项目:AndroidBackendlessChat 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Gets the current Session.
 * 
 * @return the current Session object.
 */
protected final Session getSession() {
    if (sessionTracker != null) {
        return sessionTracker.getSession();
    }
    return null;
}
FacebookFragment.java 文件源码 项目:AndroidBackendlessChat 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
FacebookFragment.java 文件源码 项目:AndroidBackendlessChat 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Gets the access token associated with the current session or null if no 
 * session has been created.
 * 
 * @return the access token
 */
protected final String getAccessToken() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        return (currentSession != null) ? currentSession.getAccessToken() : null;
    }
    return null;
}
FacebookFragment.java 文件源码 项目:AndroidBackendlessChat 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Gets the date at which the current session will expire or null if no session 
 * has been created.
 * 
 * @return the date at which the current session will expire
 */
protected final Date getExpirationDate() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getOpenSession();
        return (currentSession != null) ? currentSession.getExpirationDate() : null;
    }
    return null;
}


问题


面经


文章

微信
公众号

扫码关注公众号