我想在facebook登录后开始一项新活动。 我想要一个具有facebook登录按钮的应用程序,并在登录后输入其他活动,在本教程中,点击登录按钮后会出现注销按钮,我不想显示注销按钮。 这是我的代码。我正在使用facebook-android-sdk 4.1.2 Test是新的活动类。我想在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);
}
答案 0 :(得分:0)
写 -
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 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);
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);
Log.v("LoginActivity", response.toString());
}
});
答案 1 :(得分:0)
登录后,您必须将此行添加到您的代码中。
loginButton.setVisibility(View.INVISIBLE);
在注销后显示
显示按钮loginButton.setVisibility(View.VISIBLE);