Search code examples
androidgoogle-apigoogle-drive-apigoogle-api-java-clientgoogle-drive-android-api

"Cannot find DriveId. Are you authorized to view this file?": Even if EXISTING_FOLDER_ID is set manually


I am having a look at here from github.

I can create a file and a folder successfully by reading the code provided in github. But I am not being able to edit the file or create a file/folder in any specific folder.

The main problem would be using emulator, but I am not sure. I am using GenyMotion

I have also copied the ID of a file/folder using

showMessage("Created a file in App Folder: "
                    + result.getDriveFile().getDriveId());

and

showMessage("Created a folder: " + result.getDriveFolder().getDriveId());

lines of code .

Then I changed

public static final String EXISTING_FOLDER_ID = "CAESABjACiCShczj8lI=";//changed this
    public static final String EXISTING_FILE_ID = "0ByfSjdPVs9MZTHBmMVdSeWxaNTg";

of BaseActivity. Still I am getting the same output.

"Cannot find DriveId. Are you authorized to view this file?"

Can anyone point me what am I doing wrong here?

Thank you!!


Solution

  • I do believe that 'result.getDriveFile().getDriveId()' gives you a 'DriveId', an ID used by GDAA only. The 'EXISTING_FILE_ID' refers to another ID, so called ResourceID. You have to use that one. See SO 21800257. The ResourceId is the original ID used in older RESTful API, and the only one that you can use when referring to the Drive object across different devices (DriveID is device specific). ResourceID can also be seen as a part of the URL address of the object.

    BTW. the shortest answer to your question is:

    result.getDriveFile().getDriveId().getResourceId();
    

    But you may get NULL if you're too quick see SO 22874657 .

    Good Luck.