com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException при работе в google drive

Мне необходимо реализовать синхронизацию с помощью Google Drive.Реализовывал с помощью вот этого гайда https://github.com/mesadhan/google-drive-app При запросе файлов получаю исключение: com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException

Вот код: MainActivity:

    LinearLayout llSysncSd = profileView.findViewById(llSynchSd);
            llSynch.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    googleSingInManager.openNeedFile();
                }
            });
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == AppConfiguration.GOOGLE_SIGN_IN_CODE) {
            googleSingInManager.handleSignInResult(data);
        }

Вот код GoogleSingInManager:

public class GoogleSingInManager {

    Context context;
    GoogleSignInClient googleSignInClient;
    UpdateUIMenuListener updateUIMenuListener;
    private static GoogleSingInManager googleSingInManagerInstance;
    private UserConfig userConfig;
    public DriveServiceHelper mDriveServiceHelper;

    public static GoogleSingInManager getGoogleSingInManagerInstance(Context context, UpdateUIMenuListener updateUIMenuListener){
        if(googleSingInManagerInstance==null){
            return  googleSingInManagerInstance = new GoogleSingInManager(context, updateUIMenuListener);
        }else{
            return googleSingInManagerInstance;
        }
    }

    private GoogleSingInManager(Context context, UpdateUIMenuListener updateUIMenuListener) {
        this.context = context;
        this.updateUIMenuListener = updateUIMenuListener;
        userConfig = UserConfig.getInstance(context);

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
                .build();

        googleSignInClient = GoogleSignIn.getClient(context, gso);
        GoogleAccountCredential credential =
                GoogleAccountCredential.usingOAuth2(
                        context, Collections.singleton(DriveScopes.DRIVE_FILE));
        GoogleSignInAccount googleAccount = GoogleSignIn.getLastSignedInAccount(context);
        if(googleAccount != null) {
            credential.setSelectedAccount(googleAccount.getAccount());
            Drive googleDriveService =
                    new Drive.Builder(
                            AndroidHttp.newCompatibleTransport(),
                            new GsonFactory(),
                            credential)
                            .setApplicationName("App App Pro")
                            .build();

            // The DriveServiceHelper encapsulates all REST API and SAF functionality.
            // Its instantiation is required before handling any onClick actions.
            mDriveServiceHelper = new DriveServiceHelper(googleDriveService);
        }
    }

    public void setUpdateUIMenuListener(UpdateUIMenuListener updateUIMenuListener){
        this.updateUIMenuListener = updateUIMenuListener;
    }


    public void signIn() {
        // Launches the sign in flow, the result is returned in onActivityResult
        Intent intent = googleSignInClient.getSignInIntent();
        intent.setFlags(0);
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(intent, AppConfiguration.GOOGLE_SIGN_IN_CODE);
        } else {
            Log.e("CameraApp", "mContext should be an instanceof Activity.");
        }
    }

    //замена с учетом google drive
    public void handleSignInResult(Intent result) {
        GoogleSignIn.getSignedInAccountFromIntent(result)
                .addOnSuccessListener(googleAccount -> {
                    L.i("Signed in as " + googleAccount.getEmail());
                    userConfig.setUserName( googleAccount.getDisplayName());
                    userConfig.setUserEmail( googleAccount.getEmail() );
                    userConfig.setPhotoUri(googleAccount.getPhotoUrl());
                    // Use the authenticated account to sign in to the Drive service.
                    GoogleAccountCredential credential =
                            GoogleAccountCredential.usingOAuth2(
                                    context, Collections.singleton(DriveScopes.DRIVE_FILE));
                    credential.setSelectedAccount(googleAccount.getAccount());
                    Drive googleDriveService =
                            new Drive.Builder(
                                    AndroidHttp.newCompatibleTransport(),
                                    new GsonFactory(),
                                    credential)
                                    .setApplicationName("Camera App Pro")
                                    .build();

                    // The DriveServiceHelper encapsulates all REST API and SAF functionality.
                    // Its instantiation is required before handling any onClick actions.
                   mDriveServiceHelper = new DriveServiceHelper(googleDriveService);
                })
                .addOnFailureListener(exception ->
                        L.e("Unable to sign in." + exception));
    }

public void openNeedFile() {
        if (mDriveServiceHelper != null) {
            mDriveServiceHelper.queryFiles().addOnSuccessListener(fileList -> {
                List<File> files = fileList.getFiles();
                L.i("Не работает")
            }).addOnFailureListener(exception -> {
                L.i("Fail");
            });
        }
    }
}

Вот код DriveServiceHelper:

    public class DriveServiceHelper {
    public Task<FileList> queryFiles() {
            return Tasks.call(mExecutor, new Callable<FileList>() {
                @Override
                public FileList call() throws Exception {
                    return mDriveService.files().list().setSpaces("drive").execute();
                }
            });
        }

}

А и вот в манифесте добавил:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />

Дело в том что тут уже была авторизация через гугл, которую я же и делал. И вот теперь заказчик захотел реализации синхронизации файлов. Надо ли донастраивать гугл консоль (https://console.cloud.google.com/projectselector2/apis/dashboard) ведь у меня есть уже настройка для авторизации и она работает? Я не настраивал google консоль, по причине уже настроенной OAuth там для авторизации, только включил Google Drive Api. Что это вообще может быть, может надо что то еще добавить в коде или же это скорее неправильно настроенная консоль или еще добавить 1 OAuth для google drive?


Ответы (0 шт):