2017-11-21 20 views
0

현재 Firebases 시스템을 사용하여 내 앱에 로그인 기능을 만들려고합니다. 어떤 이유로 든 mGoogleSignInClient = GoogleSignIn.getClient(this, gso); 행이 작동하지 않습니다. GoogleSignIn.getClient은 빨간색입니다. 필자는 다양한 자습서를 살펴 보았지만 아무도이 문제가없는 것 같습니다. 이 문제에 도움이되기를 바랍니다. MY GRADLES https://gist.github.com/kakashidota/198e5253e168243e985be64fc93f1c9b https://gist.github.com/kakashidota/0a96ee860aff79dd70df67636d2b081fAndroid 앱에서 Firebase 로그인을 사용하는 데 문제가 있음

package se.iths.apostolidis.quickmaths; 


import android.content.Intent; 
import android.os.Bundle; 
import android.support.annotation.NonNull; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import com.google.android.gms.auth.api.signin.GoogleSignInAccount; 
import com.google.android.gms.auth.api.signin.GoogleSignInOptions; 
import android.widget.Toast; 
import com.google.android.gms.common.api.ApiException; 
import com.google.android.gms.tasks.OnCompleteListener; 
import com.google.android.gms.tasks.Task; 
import com.google.firebase.auth.AuthCredential; 
import com.google.firebase.auth.AuthResult; 
import com.google.firebase.auth.FirebaseAuth; 
import com.google.firebase.auth.FirebaseUser; 
import com.google.firebase.auth.GoogleAuthProvider; 

public class LoginActivity extends AppCompatActivity { 

    //a constant for detecting the login intent result 
    private static final int RC_SIGN_IN = 234; 

    //Tag for the logs optional 
    private static final String TAG = "simplifiedcoding"; 

    //creating a GoogleSignInClient object 
    GoogleSignInAccount mGoogleSignInClient; 

    //And also a Firebase Auth object 
    FirebaseAuth mAuth; 

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

     //first we intialized the FirebaseAuth object 
     mAuth = FirebaseAuth.getInstance(); 

     //Then we need a GoogleSignInOptions object 
     //And we need to build it as below 
     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestIdToken(getString(R.string.default_web_client_id)) 
       .requestEmail() 
       .build(); 

     //Then we will get the GoogleSignInClient object from GoogleSignIn class 
     mGoogleSignInClient = GoogleSignIn.getClient(this, gso); 

     //Now we will attach a click listener to the sign_in_button 
     //and inside onClick() method we are calling the signIn() method that will open 
     //google sign in intent 
     findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       signIn(); 
      } 
     }); 
    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 

     //if the user is already signed in 
     //we will close this activity 
     //and take the user to profile activity 
     if (mAuth.getCurrentUser() != null) { 
      finish(); 
      startActivity(new Intent(this, ProfileActivity.class)); 
     } 
    } 


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

     //if the requestCode is the Google Sign In code that we defined at starting 
     if (requestCode == RC_SIGN_IN) { 

      //Getting the GoogleSignIn Task 
      Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); 
      try { 
       //Google Sign In was successful, authenticate with Firebase 
       GoogleSignInAccount account = task.getResult(ApiException.class); 

       //authenticating with firebase 
       firebaseAuthWithGoogle(account); 
      } catch (ApiException e) { 
       Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show(); 
      } 
     } 
    } 

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 
     Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); 

     //getting the auth credential 
     AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 

     //Now using firebase we are signing in the user here 
     mAuth.signInWithCredential(credential) 
       .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         if (task.isSuccessful()) { 
          Log.d(TAG, "signInWithCredential:success"); 
          FirebaseUser user = mAuth.getCurrentUser(); 

          Toast.makeText(LoginActivity.this, "User Signed In", Toast.LENGTH_SHORT).show(); 
         } else { 
          // If sign in fails, display a message to the user. 
          Log.w(TAG, "signInWithCredential:failure", task.getException()); 
          Toast.makeText(LoginActivity.this, "Authentication failed.", 
            Toast.LENGTH_SHORT).show(); 

         } 

         // ... 
        } 
       }); 
    } 


    //this method is called on click 
    private void signIn() { 
     //getting the google signin intent 
     Intent signInIntent = mGoogleSignInClient.getSignInIntent(); 

     //starting the activity for result 
     startActivityForResult(signInIntent, RC_SIGN_IN); 
    } 
} 

답변

0

당신은 여기에 뭔가 잘못하고있는 TO 링크 :

편집 할 수 있습니다. // GoogleSignInClient 객체 만들기> GoogleSignInAccount mGoogleSignInClient; 계정을 GoogleSigninClient로 변경해야 클라이언트 가져 오기를 수행 할 때만이 반환 유형에 대한 클라이언트 인스턴스를 얻을 수 있습니다. // GoogleSignIn 클래스에서 GoogleSignInClient 객체를 가져옵니다. mGoogleSignInClient = GoogleSignIn.getClient (this, gso);

GoogleSignInAccount -> GoogleSignInClient로 변경

+0

GoogleSignInClient – Kakashi

+0

라는 그런 것은 없다 https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/ GoogleSignInClient이 링크를 클릭하면 GoogleSignInClient에 대한 참조를 얻을 수 있습니다. –

+0

안녕 친구, 도와 줘서 고마워. 필자는 그 문서를 보았고 그것을 이해하지 못합니다. 2 개월 동안 만 코드화했습니다. – Kakashi