私はAndroid用アプリケーションでFacebook Loginを使用しています。私は正常にログインし、TextViewにユーザー名を表示することができますが、私は以下の問題に直面していますAndroidのアクティビティでFacebookフレンドリストを取得するその他のユーザーログインしている場所
私はアプリケーションを閉じて再び開くと、フェイスブックのログイン後、私はログアウトボタンを取得しています。私は、アクティビティが再びfacebook APIを呼び出してユーザー名を取得する必要があります。
私は私のOnCreateイベントで 以下のコードを使用しています
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_login);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.connectWithFbButton);
loginButton.setReadPermissions("email", "user_friends");
loginButton.registerCallback(callbackManager, nCallback);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode,resultCode,data);
}
private FacebookCallback<LoginResult> nCallback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
if (profile!= null)
{
String FirstName = "";
String LastName = "";
String ProfilePic = "";
String PId = "";
FirstName = URLEncoder.encode(profile.getFirstName(), "utf-8");
LastName = URLEncoder.encode(profile.getLastName(), "utf-8");
message.setText("Hello " + profile.getFirstName());
}
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
};