Недопустимая область аутентификации Facebook в Android Studio - PullRequest
0 голосов
/ 11 сентября 2018

Я использую фрагменты во всем своем классе. Так что проблема в том, что когда я нажимаю «Войти» в Facebook, а затем после этого говорит «Invalid Scope: SignInFragment», SignInFragment является классом.

Это изображение, когда я нажимал кнопку входа в Facebook: enter image description here

Это код для: SignInFragment

import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;


import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
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.FacebookAuthProvider;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;


import java.util.Arrays;

public class SignInFragment extends Fragment implements View.OnClickListener {

private static final String TAG = "SignInFragment";

private TextView mEmail, mPassword, mHeading, mToRegister, mFckyou;
private EditText eEmail, ePassword;
private Button btnSignin;
private ProgressBar mProgressBar;

//Firebase
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;

//Facebook
private CallbackManager callbackManager;
private LoginButton loginButton;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.signin_fragment, container, false);

    //TextView
    mEmail = view.findViewById(R.id.tvEmail);
    mPassword = view.findViewById(R.id.tvPassword);
    mHeading = view.findViewById(R.id.heading);
    mToRegister = view.findViewById(R.id.toRegister);
    mFckyou = view.findViewById(R.id.fckyou);
    //EditText
    eEmail = view.findViewById(R.id.etEmail);
    ePassword = view.findViewById(R.id.etPassword);
    //Changing the font style of hint
    eEmail.setTypeface(Typeface.SANS_SERIF);
    ePassword.setTypeface(Typeface.SANS_SERIF);
    //Button
    btnSignin = view.findViewById(R.id.btnSignin);
    //ProgressBar
    mProgressBar = view.findViewById(R.id.progressBar);
    //Facebook
    loginButton = view.findViewById(R.id.login_button);
    //Firebase
    mAuth = FirebaseAuth.getInstance();

    //Progress Bar and Text view = GONE
    mProgressBar.setVisibility(View.GONE);
    mFckyou.setVisibility(View.GONE);

    setupFbAuth();
    navigateToReigster();
    setupFirebaseAuth();
    signInUser();

    return view;
}

/*
---------------------------------------Facebook-------------------------------------------
 */

public void setupFbAuth(){

    callbackManager = CallbackManager.Factory.create();
    loginButton.setReadPermissions(Arrays.asList(TAG));
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            handleFacebookAccessToken(loginResult.getAccessToken());

        }

        @Override
        public void onCancel() {

            Toast.makeText(getActivity(), "Cancelling...", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onError(FacebookException error) {

            Log.d(TAG, "onError: error" + error.getMessage());

        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    callbackManager.onActivityResult(requestCode,resultCode,data);
    super.onActivityResult(requestCode, resultCode, data);
    Fragment fragment = getFragmentManager().findFragmentById(R.id.container);
    fragment.onActivityResult(requestCode, resultCode, data);
}

private void handleFacebookAccessToken(AccessToken accessToken) {
    Log.d(TAG, "handleFacebookAccessToken: " + accessToken);

    AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (task.isSuccessful()){
                        Toast.makeText(getActivity(), "Signed in success!", Toast.LENGTH_SHORT).show();
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI(user);
                    }else {

                        Toast.makeText(getActivity(), "Authentication Failed", Toast.LENGTH_SHORT).show();
                    }

                }
            });
}

private void updateUI(FirebaseUser user) {

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.container, new HomeActivity());
    ft.commit();
}
...