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);
    }
}

誰でも私がここで間違っていることを指摘できますか?

4

1 に答える 1