[英]Android, Facebook login doesn't work when the Facebook application is installed
我正在開發一個應與Facebook連接的應用程序,我遵循了Facebook教程,並將哈希鍵也插入了Facebook儀表板。
我能夠與Facebook連接,但是在安裝Facebook應用程序后,我再也無法與Facebook連接,會話狀態已關閉。
我讀了幾個主題,但是找不到適合我問題的解決方案,所以我決定發布我的問題,您對我的問題有任何想法嗎?
按照我的源代碼
public class FragmentSn extends Fragment {
private static final String TAG = "FragmentSn";
private UiLifecycleHelper uiHelper;
static boolean fbLoggedIn;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragmentsn, container, false);
LoginButton authButton = (LoginButton) rootView.findViewById(R.id.authButton);
authButton.setReadPermissions(Arrays.asList("basic_info", "email"));
authButton.setFragment(this);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@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, new
FacebookDialog.Callback(){
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error,
Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
}
@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);
}
private 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()) {
fbLoggedIn=true;
} else if (state.isClosed()) {
fbLoggedIn=false;
}
}
}
MainActivity源代碼
public class MainActivity extends ActionBarActivity {
// Declare Tab Variable
ActionBar.Tab Tab1, Tab2, Tab3,Tab4;
Fragment fragmentMap = new FragmentMap();
Fragment fragmentCoupon = new FragmentCoupon();
Fragment fragmentCampaign = new FragmentCampaign();
Fragment fragmentSn = new FragmentSn();
Tools tools;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
// Hide Actionbar Icon
actionBar.setDisplayShowHomeEnabled(false);
// Hide Actionbar Title
actionBar.setDisplayShowTitleEnabled(false);
// Create Actionbar Tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Set Tab Icon and Titles
Tab1 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_map));
Tab2 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_coupon));
Tab3 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_campaign));
//Tab4 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_sn));
// Set Tab Listeners
Tab1.setTabListener(new TabListener(fragmentMap));
Tab2.setTabListener(new TabListener(fragmentCoupon));
Tab3.setTabListener(new TabListener(fragmentCampaign));
//Tab4.setTabListener(new TabListener(fragmentSn));
// Add tabs to actionbar
actionBar.addTab(Tab1);
actionBar.addTab(Tab2);
actionBar.addTab(Tab3);
//actionBar.addTab(Tab4);
// Facebook - START
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
fragmentSn = new FragmentSn();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, fragmentSn)
.commit();
} else {
// Or set the fragment from restored state info
fragmentSn = (FragmentSn) getSupportFragmentManager().findFragmentById(android.R.id.content);
}
// Facebook - END
// AM 2014/01/15 - START
//Check update information
tools = new Tools(this.getApplicationContext());
// AM 2014/01/15 - END
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
期待您的回復,謝謝
我之前也遇到過這個問題,重新創建調試密鑰為我解決了這個問題。 請注意,您可以在Facebook應用程序配置文件中添加多個密鑰,您可能希望至少從所有開發機中添加調試密鑰以及發布密鑰。
我不知道為什么,但是在以與現在相同的方式重新創建了骨灰之后,將程序插入到Facebook儀表板中,程序開始正確接收Facebook應用程序的信息。
感謝chintak khetiya的回復。
您在使用模擬器嗎? 如果是這樣,請嘗試使用ARM版本。 Facebook LoginActivity在Intel模擬器上崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.