我正在开发一个应该与Facebook连接的应用程序,我遵循facebook教程并在Facebook仪表板中插入了散列键。当Facebook应用程序安装时,Android和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);
}
}
期待您的回复,谢谢
https://developers.facebook.com/docs/android/login-with-facebook/将你的散列键与给定的代码相匹配以生成散列键programmactily是否相同 –
感谢chintan的回复,但不幸的是我检查了hask键更多时间和它匹配。 –
有默认的登录例子,只需下载最新的sdk并尝试使用它。 –