googleworkspace / android-samples

Android samples for Google Workspace APIs
Apache License 2.0
635 stars 410 forks source link

ApiException: 1502: Invalid parent folder. #72

Closed or-dvir closed 5 years ago

or-dvir commented 6 years ago

first of all i have seen this issue https://github.com/googledrive/android-demos/issues/35 but it does not apply to me since i am not using drive/resource id to create the file.

so here's my problem: i am trying to create a text file inside the app folder and i am getting this error: com.google.android.gms.common.api.ApiException com.google.android.gms.common.api.ApiException: 1502: Invalid parent folder. at com.google.android.gms.internal.zzbsv.onError(Unknown Source) at com.google.android.gms.internal.zzbql.onTransact(Unknown Source) at android.os.Binder.execTransact(Binder.java:565)

first i look for the file in the folder:

final Task<DriveFolder> taskGetAppFolder = getDriveResourceClient().getAppFolder();
        taskGetAppFolder.continueWithTask(new Continuation<DriveFolder, Task<MetadataBuffer>>()
        {
            @Override
            public Task<MetadataBuffer> then(@NonNull Task<DriveFolder> task) throws Exception
            {
                //querying for our file in the app folder of the users' google drive
                Query query = new Query.Builder()
                        .addFilter(Filters.eq(SearchableField.TITLE, Utils.GOOGLE_DRIVE_FILE_NAME))
                        .addFilter(Filters.eq(SearchableField.MIME_TYPE, "text/plain"))
                        .build();

                return getDriveResourceClient().queryChildren(task.getResult(), query);
            }
        }).continueWith(new Continuation<MetadataBuffer, Void>()
        {
            @Override
            public Void then(@NonNull Task<MetadataBuffer> task) throws Exception
            {
                boolean isReadingFileFromDrive = false;
                EventReadUserFavoriteShows driveEvent = new EventReadUserFavoriteShows();

                //file does not exist in google drive
                if (task.getResult().getCount() == 0)
                {
                    createGoogleDriveFile(taskGetAppFolder.getResult());
                }

                                //some more code

and here is the creation of the file:

private void createGoogleDriveFile(final DriveFolder appFolder)
    {
        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                .setTitle(Utils.GOOGLE_DRIVE_FILE_NAME)
                .setMimeType("text/plain")
                .build();

        //when DriveContents is null, it just created an empty file
        Task<DriveFile> taskCreateFile =
                getDriveResourceClient().createFile(appFolder ,changeSet, null);
        taskCreateFile
                .addOnSuccessListener(BaseActivity.this, new OnSuccessListener<DriveFile>()
                {
                    @Override
                    public void onSuccess(DriveFile driveFile)
                    {
                        //todo save file id for next time?????????????
                        Toast.makeText(BaseActivity.this,
                                       R.string.createGoogleDriveFileSuccess,
                                       Toast.LENGTH_LONG)
                             .show();
                    }
                })
                .addOnFailureListener(BaseActivity.this, new OnFailureListener()
                {
                    @Override
                    public void onFailure(@NonNull Exception e)
                    {
                        Log.e(TAG, e.getClass().getName(), e);
                        Utils.makeSimpleDialog(BaseActivity.this,
                                               R.string.errorTitle,
                                               R.string.errorCreatingGoogleDriveFile,
                                               R.string.ok,
                                               null);
                    }
                });
    }

this has worked in the past but all of a sudden stopped working at all and i receive the above exception. i have tried to remove/disconnect the app from my google drive and also reinstall it on my phone but still getting the exception.

erickoledadevrel commented 5 years ago

It looks like this issue is related to custom code you wrote, and not the samples as they exist in this repo. If so, please consult the support options listed here:

https://developers.google.com/drive/android/support