Cannot access Google Drive file

大城市里の小女人 提交于 2019-12-08 12:03:13

问题


I am making a notepad app using Google Drive. Whenever user creates a file in the app, it also creates a file in the Google Drive. And user can enter the text and save the file, the unsaved text will get committed whenever the internet is available. I am managing the update and create processes within the app using the DriveId.

If the user wants to use the files with the alternative device using my app, for that I also have the option called DriveId import. By clicking the option DriveId import user will be prompted with the input box for entering the existing DriveId. Using the DriveId I thought of opening the files, But it was giving an error.

Then I saw an answer given in this SO which clearly says DriveId can be used only inside the app and device which created the file.

I also found a similar question like mine in here SO But I can’t get my problem solved. I have taken ResourceId using result.getDriveFolder().getDriveId().getResourceId()

How to read the data’s programmatically using the ResourceID? As said in the above answer here I don’t want to change the track and go into Drive REST API. Is there a way that I can read the data using Google Drive Android API ? I have done all the development process, but in the ending when I try to access from other device it is giving the error. Totally struck.

If I can only read the data using REST API any simple code will be appreciated. Thanks in advance.


回答1:


Finally Solved the DriveId Issue without REST API.

To get DriveId on the alternative device. You will need resourceId. You can use following code:-

String resourseId = "xxxxxxxxxxxxx" 

Drive.DriveApi.fetchDriveId(mGoogleApiClient,resourseId).setResultCallback(idCallBack);

private ResultCallBack<DriveApi.DriveResult> idCallBack = new ResultCallback<DriveApi.DriveIdResult>() {
    @Override
    public void onResult(DriveApi.DriveIdResult driveIdResult) {
        msg.Log("onResult");

    DriveId id = driveIdResult.getDriveId(); //Here you go :)

    }
}


来源:https://stackoverflow.com/questions/29149212/cannot-access-google-drive-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!