我想在Facebook登錄後開始一項新活動。 我想要一個具有Facebook登錄按鈕並且登錄後進入其他活動的應用程序,在本教程中,當我單擊登錄按鈕後,登出按鈕出現,我不希望登出按鈕出現。 這是我的代碼。我正在使用facebook-android-sdk 4.1.2 測試是新的活動類。我想在Facebook登錄後打開它。使用Facebook登錄按鈕登錄並開始新活動
TextView info;
private LoginButton loginButton;
private CallbackManager callbackManager;
String name;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.fb_button);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("public_profile, email, user_birthday, user_friends"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
// URL image_value = new URL("http://graph.facebook.com/"+id+"/picture");
name = object.getString("email");
} catch (JSONException e) {
e.printStackTrace();
}
// getting email of the use
info.setText(name);
Log.v("LoginActivity", response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
Intent intent = new Intent(FbActivity.this, Test.class);
FbActivity.this.startActivity(intent);
}
@Override
public void onCancel() {
info.setText("Login attempt canceled.");
}
@Override
public void onError(FacebookException e) {
info.setText("Login attempt failed.");
}
});
// Execute DownloadJSON AsyncTask
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
Intent intent = new Intent(FbActivity.this, Test.class);
FbActivity.this.startActivity(intent);
}
什麼問題顯示按鈕? –