1

一段时间以来,我一直在努力解决这个问题。我知道还有其他类似时尚的帖子,但我似乎无法得到任何工作。我有一个问题,如果 Facebook 应用程序在模拟器上,它将无法正确登录。

发生的情况是,当用户点击登录按钮时,会弹出一个小对话框并询问他们应用程序是否可以从他们那里获得这些东西(权限)。你点击OK,它让你回来,没有任何改变......

我查看了我的 LOGCAT,发现它反复显示:每次按下按钮时都已注销(两次)。

如果模拟器上未安装 FB,则可以登录。

这是我的代码:

FBInit - 片段活动处理程序:

public class FBInit extends FragmentActivity {

private FBInitFragment fbInitFrag;


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fbinit);

    final ActionBar actionBar = getActionBar();
    actionBar.hide();

    if (savedInstanceState == null) {
        // Add the fragment on initial activity setup
        fbInitFrag = new FBInitFragment();
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, fbInitFrag).commit();
    } else {
        // Or set the fragment from restored state info
        fbInitFrag = (FBInitFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
    }

    findViewById(R.id.fb_init_next).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", 1);
            setResult(RESULT_OK, returnIntent);
            finish();
        }
    });
    findViewById(R.id.fb_init_back).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", 1);
            setResult(RESULT_CANCELED, returnIntent);
            finish();
        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.fbinit, menu);
    return true;
}



}

FBInitFragment:

public class FBInitFragment extends Fragment {

private static final String TAG = "FBInitFragment";

private UiLifecycleHelper uiHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_fbinit, container, false);

    LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
    authButton.setFragment(this);

    return view;
}

private final Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (state.isOpened()) {
        Log.i(TAG, "Logged in...");
    } else if (state.isClosed()) {
        Log.i(TAG, "Logged out...");
    }
}

@Override
public void onResume() {
    super.onResume();
    // For scenarios where the main activity is launched and user
    // session is not null, the session state change notification
    // may not be triggered. Trigger it if it's open/closed.
    Session session = Session.getActiveSession();
    if (session != null && (session.isOpened() || session.isClosed())) {
        onSessionStateChange(session, session.getState(), null);
    }

    uiHelper.onResume();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}
}

请指教!!

谢谢

安迪

4

1 回答 1

3

这意味着您的密钥哈希在您的应用设置中设置不正确。

请参阅本节获取您的密钥哈希并正确设置它们:https ://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/#create-app

于 2013-09-12T23:59:38.427 回答