我一直在讨论这个问题一段时间了。我知道还有其他类似时尚的帖子,但我似乎无法得到任何工作。我有一个问题,如果Facebook应用程序在模拟器上,它将无法正常登录。
当用户点击登录按钮时,会弹出一个小对话框并询问他们是否可以从中获取这些内容(权限)。你点击确定,它会让你回来,没有任何改变....
我看看我的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);
}
}
请指教!!
由于
安迪
答案 0 :(得分:3)
这意味着您的应用设置中的键哈希值设置不正确。
有关获取密钥哈希并正确设置的信息,请参阅此部分:https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/#create-app