2015-06-20 149 views
-1

我想在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); 
} 
+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()); 
         } 
        }); 
+0

即使這不起作用。任何人都可以幫忙嗎? –

+0

@Himanshu Shrimali你的問題是什麼? – NehaK

+0

當我點擊繼續在Facebook的確認登錄頁面上打開一個新的活動時,它首先顯示我以前的活動幾秒鐘,然後打開實際活動。你能幫忙嗎? –

0

您必須在登錄後爲此代碼添加此行。

loginButton.setVisibility(View.INVISIBLE); 

記住後註銷與

loginButton.setVisibility(View.VISIBLE);