facebook 登錄

第一步:

首先要導入facebook庫,如圖


第二步:

    1、  首先查看是否有相應的SessionState.CREATED_TOKEN_LOADED,

        Session session = Session.getActiveSession();
        if (session == null)
        {

            if (session == null)
            {
                session = new Session(mstaticContext);
            }
            Session.setActiveSession(session);
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED))
            {
                session.openForRead(new Session.OpenRequest(mstaticContext)
                        .setCallback(mstatusCallback));
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED))
            {
                return true;
            }
            else
            {
                return false;
            }
        }


     2、如果沒有直接登錄,彈出登錄框

             Session session = Session.getActiveSession();
        if (!session.isOpened() && !session.isClosed())
        {
            session.openForRead(new Session.OpenRequest(mstaticContext)
                    .setCallback(mstatusCallback));
        } else
        {
            Session.openActiveSession(mstaticContext, true, mstatusCallback);
        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章