隨着新的Android和與Facebook SDK但Facebook的登錄嘗試通過以下的link與片段
登錄因爲他們說會做的登錄過程與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);
}
}
任何人都可以指出我在做錯誤的here.Thanks任何答覆,這個Facebook登錄新的3.0卡住三服。
我缺少的部分是:_facebookLoginButton.setFragment(本);謝謝!這個例子有幫助。 – bentzy
我做了像@Benny一樣的錯誤.. –
@笨蛋,我不相信它!我已經找了兩個小時了,不明白問題在哪裏。謝謝!!! – offset