Facebook注销删除个人资料图片和名称

时间:2015-06-05 14:18:12

标签: android facebook facebook-sdk-4.0

我遇到删除问题,并在退出时从Facebook重置文本。图片和名字仍在那里。

        /// Logged OUT \\\ ---- The problem
    if (profile == null) {
        profilePictureView.setProfileId(null);
        name.setText("Anonymous user");
        System.out.print("Profile == null!");
    }

使用此代码将进程设置配置文件图片处理为空白,并将名称设置为“匿名用户”。这对我不起作用。有人可以提供帮助吗?

下面你可以看到我的部分代码。

public class Profile extends Activity {
/**
 * Called when the activity is first created.
 */

WebView web;
ArrayList<NavigationDrawerItem> listItems;
DrawerLayout drawerLayout;
ActionBarDrawerToggle drawerToggle;
ListView list;

private CallbackManager callbackManager;
private ProfilePictureView profilePictureView;
private TextView name;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_profile);
    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile", "email", "user_friends");
    com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();
    final ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.profilepic);
    final TextView name = (TextView) findViewById(R.id.name);


    /// Logged IN \\\
        if (profile != null) {
            profilePictureView.getProfileId();
            profilePictureView.setProfileId(profile.getId());
            name.setText(profile.getName());
        }

    /// Logged OUT \\\ ---- The problem
    if (profile == null) {
        profilePictureView.setProfileId(null);
        name.setText("Anonymous user");
        System.out.print("Profile == null!");
    }


    final SharedPreferences sharedPrefs = getSharedPreferences("details", MODE_PRIVATE);
    //After referencing your Views, add this.
    String nameStr = sharedPrefs.getString("name", null);
    String idStr = sharedPrefs.getString("id", null);
    AccessToken token = AccessToken.getCurrentAccessToken();
    if (token != null) {
        if (nameStr != null) name.setText(nameStr);
        if (idStr != null) profilePictureView.setProfileId(idStr);
    }
    //.. Do the same for other profile data


        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

            @Override
            public void onSuccess(LoginResult loginResult) {
                AccessToken accessToken = loginResult.getAccessToken();
                com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();
                profilePictureView.getProfileId();
                profilePictureView.setProfileId(profile.getId());
                name.setText(profile.getName());

                SharedPreferences.Editor editor = sharedPrefs.edit();
                editor.putString("name", profile.getName());
                editor.putString("id", profile.getId());
                //.. Do the same for other profile data
                editor.commit();

            }


            @Override
            public void onCancel() {
                // App code
            }


            @Override
            public void onError(FacebookException exception) {
                // App code
                Log.i("Error", "Error");
            }

        });

&lt; - 代码的其余部分 - &gt;

1 个答案:

答案 0 :(得分:0)

为了实现这一目标,您必须覆盖onCurrentAccessTokenChanged方法。

示例:

AccessTokenTracker accessTokenTracker= new AccessTokenTracker() 
{
     @Override
     protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {
          if (newToken == null){
             info.setText(" ");
             profilePictureView.setProfileId(null);
          }
      }
};

上面的代码应该进入onCreate方法。