2015-07-14 2 views
-1

У меня есть следующий код, но я не знаю, какой метод выполняет, когда я нажимаю Logout. Мне нужно знать только, какой метод выполняется при выходе из системы. Или другое решение? Спасибо за все :) dasasaЯ не знаю, как использовать LOGOUT в API FACEBOOK ANDROID

public class FBLoginFragment extends Fragment implements IServiceCallback { 

private CallbackManager callbackManager; 
private TextView textView; 

private AccessTokenTracker accessTokenTracker; 
private ProfileTracker mProfileTracker; 

private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() { 

    @Override 
    public void onSuccess(LoginResult loginResult) { 
     mProfileTracker = new ProfileTracker() { 
      @Override 
      protected void onCurrentProfileChanged(Profile profile, Profile profile2) { 
       mProfileTracker.stopTracking(); 
      } 
     }; 
     mProfileTracker.startTracking(); 
     AccessToken accessToken = loginResult.getAccessToken(); 
     Profile profile = Profile.getCurrentProfile(); 
     displayMessage(profile); 

    } 

    @Override 
    public void onCancel() { 

    } 

    @Override 
    public void onError(FacebookException e) { 

    } 
}; 

public FBLoginFragment() { 

} 


@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); 

    callbackManager = CallbackManager.Factory.create(); 

    accessTokenTracker= new AccessTokenTracker() { 
     @Override 
     protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { 

     } 
    }; 

    mProfileTracker = new ProfileTracker() { 
     @Override 
     protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { 
      displayMessage(newProfile); 
      if(newProfile != null){ 
       register(newProfile); 
      } 

     } 
    }; 



    accessTokenTracker.startTracking(); 
    mProfileTracker.startTracking(); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    return inflater.inflate(R.layout.facebook_fragment, container, false); 
} 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button); 
    textView = (TextView) view.findViewById(R.id.textView); 

    loginButton.setReadPermissions(Arrays.asList("public_profile", "user_friends")); 
    loginButton.setFragment(this); 
    loginButton.registerCallback(callbackManager, callback); 

} 

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

private void displayMessage(Profile profile){ 
    if(profile != null){ 
     textView.setText(profile.getName()); 
    } 
} 

private void register(Profile profile){ 
    if(profile != null){ 
     new Register(this).run(profile); 
    } 

} 

@Override 
public void onStop() { 
    super.onStop(); 
    accessTokenTracker.stopTracking(); 
    mProfileTracker.stopTracking(); 
} 
@Override 
public void onResume() { 
    super.onResume(); 
    Profile profile = Profile.getCurrentProfile(); 
    displayMessage(profile); 
} 

@Override 
public void onSuccess(JSONObject obj, String method) throws JSONException { 
    User user = new User(obj); 
    user.insert(); 

    //Intent intent = new Intent(getActivity(), Update.class); 
    //startActivity(intent); 
} 

@Override 
public void onError(String error) { 

} 

ответ

0

Вы должны получить активную сессию, то затем вызвать closeAndClearTokenInformation().

Вы можете получить текущий активный сеанс через Session.getActiveSession().

+0

но, где? в каком методе? –

+0

Везде, где вы хотите вывести пользователя из системы. Там, где вы делаете это, полностью зависит от вас. –

0

Попробуйте этот метод, чтобы выйти из Facebook программно в Android

/** * Выход из Facebook */

государственной статической силы callFacebookLogout (контекст Context) {

Session session = Session.getActiveSession(); 
if (session != null) { 

    if (!session.isClosed()) { 
     session.closeAndClearTokenInformation(); 
     //clear your preferences if saved 
    } 
} else { 

    session = new Session(context); 
    Session.setActiveSession(session); 

    session.closeAndClearTokenInformation(); 
     //clear your preferences if saved 
    } 

}