5

作为 android 和 facebook sdk 的新手,但尝试按照以下方式登录链接登录

正如他们所说,它将使用 facebook 进行登录过程,但没有任何反应,并且每次都显示注销状态。这里是活动课。

 public class MYFaceLoginActivity extends FragmentActivity {

        private LoginFragment loginfragment; 

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // TODO Auto-generated method stub
            if(savedInstanceState==null)
            {
                loginfragment=new LoginFragment();
                getSupportFragmentManager().beginTransaction().add(android.R.id.content, loginfragment).commit();

            }
            else
            {
                loginfragment=(LoginFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
            }


        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            //loginfragment.onActivityResult(requestCode, resultCode, data);
        }

    }

接下来是片段类

public class LoginFragment extends Fragment 
{
    private View login_view;
    private static final String TAG="LoginFragment";
    private UiLifecycleHelper uihelper;
    private LoginButton authbutton;

    private Session.StatusCallback callback=new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            // TODO Auto-generated method stub
            onSessionStatechange(session, state, exception);
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        login_view=inflater.inflate(R.layout.login_fragment, container,false);

        authbutton=(LoginButton) login_view.findViewById(R.id.authButton);
        authbutton.setFragment(this);
        authbutton.setReadPermissions(Arrays.asList("user_likes","user_status"));

        return login_view;
    }

    private void onSessionStatechange(Session session,SessionState state,Exception exception)
    {
        if(state.isOpened()){
            Log.i(TAG, "LOGGED IN....");
        }
        else
        {
            Log.i(TAG, "LOGGED OUT....");
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        uihelper=new UiLifecycleHelper(getActivity(), callback);
        uihelper.onCreate(savedInstanceState);
    }

    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        Session session=Session.getActiveSession();
        if((session!=null)&&(session.isOpened()||session.isClosed()))
        {
            onSessionStatechange(session, session.getState(), null);

        }
        uihelper.onResume();
    }

    @Override
    public void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        uihelper.onPause();
    }
    @Override
    public void onSaveInstanceState(Bundle outState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(outState);
        uihelper.onSaveInstanceState(outState);
    }
    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        uihelper.onDestroy();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        uihelper.onActivityResult(requestCode, resultCode, data);
    }
}

谁能指出我在这里做错了什么。感谢您的任何回复,并且使用此 facebook 登录新 3.0 卡了三天。

4

1 回答 1

0

请在MYFaceLoginActivity文件中进行更改

getSupportFragmentManager().beginTransaction().add(
    android.R.id.content,loginfragment).commit();

安装用途:

getSupportFragmentManager().beginTransaction().add(R.id.content, loginfragment).commit();
loginfragment=(LoginFragment) getSupportFragmentManager().findFragmentById(R.id.content);
于 2013-06-13T08:01:08.297 回答