0

Firebaseを使用してFacebookにログインし、名前、メール、プロフィール画像、uidを取得してFirebaseデータベースに保存します。firebaseのFacebook認証が動作しない

ログインボタンをクリックしてからFacebookアカウントのウィンドウがポップアップするまでは、すべて正常に機能しています。その後、「Continue With Rishabh」をクリックしてアカウントを選択すると、何も起こりません。

認証なし、エラーなし、何もありません。同じFacebookアカウント選択ウィンドウが画面に残り、何も起こりません。

ご協力いただければ幸いです。アプリケーションでこれを入れて

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_sign_in); 

     mAuth = FirebaseAuth.getInstance(); 

     mAuthListener = new FirebaseAuth.AuthStateListener() { 
      @Override 
      public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
       FirebaseUser user = firebaseAuth.getCurrentUser(); 
       if (user != null) { 
        // User is signed in 
        Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); 
       } else { 
        // User is signed out 
        Log.d(TAG, "onAuthStateChanged:signed_out"); 
       } 
       // ... 
      } 
     }; 

     mSignInToolbar = (Toolbar) findViewById(R.id.signInToolbar); 
     setSupportActionBar(mSignInToolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     mRef = FirebaseDatabase.getInstance().getReference().child("Users"); 
     mRef.keepSynced(true); 

     mEmailField = (EditText) findViewById(R.id.emailField); 
     mPasswordField = (EditText) findViewById(R.id.passowrdField); 
     mSigninBtn = (Button) findViewById(R.id.signinBtn); 
     mProgress = new ProgressDialog(this); 

     // Initialize Facebook Login button 
     FacebookSdk.sdkInitialize(getApplicationContext()); 
     mCallbackManager = CallbackManager.Factory.create(); 
     loginButton = (LoginButton) findViewById(R.id.button_facebook_login); 
     loginButton.setReadPermissions("email", "public_profile"); 
     loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() { 
      @Override 
      public void onSuccess(LoginResult loginResult) { 
       Log.d(TAG, "facebook:onSuccess:" + loginResult); 
       handleFacebookAccessToken(loginResult.getAccessToken()); 
      } 

      @Override 
      public void onCancel() { 
       Log.d(TAG, "facebook:onCancel"); 
       // ... 
      } 

      @Override 
      public void onError(FacebookException error) { 
       Log.d(TAG, "facebook:onError", error); 
       // ... 
      } 
     }); 

    } 


    @Override 
    public void onStart() { 
     super.onStart(); 
     mAuth.addAuthStateListener(mAuthListener); 
    } 


    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 

     // Pass the activity result back to the Facebook SDK 
     mCallbackManager.onActivityResult(requestCode, resultCode, data); 
    } 


    private void handleFacebookAccessToken(AccessToken token) { 
     Log.d(TAG, "handleFacebookAccessToken:" + token); 
     mProgress.setMessage("Logging in..."); 
     mProgress.show(); 

     AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); 
     mAuth.signInWithCredential(credential) 
       .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); 

         // If sign in fails, display a message to the user. If sign in succeeds 
         // the auth state listener will be notified and logic to handle the 
         // signed in user can be handled in the listener. 
         if (!task.isSuccessful()) { 
          Log.w(TAG, "signInWithCredential", task.getException()); 
          Toast.makeText(SignInActivity.this, "Authentication failed.", 
            Toast.LENGTH_SHORT).show(); 
          mProgress.dismiss(); 
         }else{ 
          String uid=task.getResult().getUser().getUid(); 
          String name=task.getResult().getUser().getDisplayName(); 
          String email=task.getResult().getUser().getEmail(); 
          String image=task.getResult().getUser().getPhotoUrl().toString(); 

          DatabaseReference childRef = mRef.child(uid); 
          childRef.child("name").setValue(name); 
          childRef.child("email").setValue(email); 
          childRef.child("image").setValue(image); 

          mProgress.dismiss(); 

          Intent mainIntent = new Intent(getApplicationContext(), MainActivity.class); 
          mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
          startActivity(mainIntent); 


         } 

        } 
       }); 
    } 
+0

問題は何ですか? –

+0

はい、Facebookの開発者ページでデフォルトの権限を変更するだけです。 –

+0

ください、私はこの同じ問題についていくつかの助けが必要です。解決策をもう少し説明していただけますか? –

答えて

2

あなたがする必要があることは、Facebookの開発者ページの一部の許可を変更することです。下の図を参照してください。あまりにも必要な許可を "はい"にしてください。 enter image description here

0
FacebookSdk.sdkInitialize(getApplicationContext()); 

は、ここに私のSignInActivity.javaです。

+0

申し訳ありませんが、すでにそこにあります。 –

+0

新しいアプリケーションを拡張する 'YourAppNameApplication'クラスを作成します。 onCreateをオーバーライドし、コードをそこに配置します。 あなたのマニフェストファイルで、 ''の下に 'android:name =" YourAppNameApplication'を入れてください。 –

+0

私もその方法を試しましたが、動作しません –

0

私は実際のデバイス(エミュレータではない)でアプリケーションを実行することで問題を解決しました。

関連する問題