简体   繁体   English

在Android上获取所有文件夹google drive api

[英]Get all folders google drive api on Android

I use the new Google drive api and I can't get All folders from my google drive, I only get the folders that I create with the google drive api... Anybody know why happens this? 我使用新的谷歌驱动器API,我无法从我的谷歌驱动器获取所有文件夹,我只获得我用谷歌驱动器api创建的文件夹...任何人都知道为什么会这样?

this is my code: 这是我的代码:

@Override
    protected void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            // Create the API client and bind it to an instance variable.
            // We use this instance as the callback for connection and connection
            // failures.
            // Since no account name is passed, the user is prompted to choose.
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        // Connect the client. Once connected, the camera is launched.
        mGoogleApiClient.connect();
    }


    /**
     * Handles resolution callbacks.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == RESULT_OK) {
            mGoogleApiClient.connect();

        }
    }

    /**
     * Called when activity gets invisible. Connection to Drive service needs to
     * be disconnected as soon as an activity is invisible.
     */
    @Override
    protected void onPause() {
        if (mGoogleApiClient != null) {
            mGoogleApiClient.disconnect();
        }
        super.onPause();
    }

    /**
     * Called when {@code mGoogleApiClient} is connected.
     */
    @Override
    public void onConnected(Bundle connectionHint) {
        Log.i(TAG, "GoogleApiClient connected");

        rootFolder = Drive.DriveApi.getRootFolder(mGoogleApiClient);

       rootFolder.listChildren(getGoogleApiClient()).setResultCallback(pruebaChildren);

    }


    ResultCallback<DriveApi.MetadataBufferResult> pruebaChildren = new
            ResultCallback<DriveApi.MetadataBufferResult>() {
                @Override
                public void onResult(DriveApi.MetadataBufferResult metadataBufferResult) {
                    if (!metadataBufferResult.getStatus().isSuccess()) {
                        showMessage("Problem while retrieving files");
                        return;
                    }
                    Log.i(TAG,"got root folder");
                    MetadataBuffer buffer = metadataBufferResult.getMetadataBuffer();
                    Log.i(TAG,"Buffer count  " + buffer.getCount());
                    if(buffer.getCount() == 0){
                        createFolderApp();
                    }
                    else{
                        for(Metadata m : buffer){
                            Log.i(TAG,"Metadata name  " + m.getTitle() + "(" + (m.isFolder() ? "folder" : "file") + ")");
                            if (m.isFolder() && m.getTitle().equals(TAG)){
                                Log.i(TAG,"APP FOLDER FOUND");
                                Drive.DriveApi.getFolder(mGoogleApiClient, m.getDriveId())
                                        .listChildren(mGoogleApiClient)
                                        .setResultCallback(foreachAppAplication);
                            }
                        }
                    }
                    return;
                }
            };

And now I want see all folders in rootFolder Drive, I try the requestSync() but the result is same... I need help please! 现在我想查看rootFolder Drive中的所有文件夹,我尝试requestSync()但结果是一样的...我需要帮助!

And another question: How I can set the AppFolder? 还有一个问题:如何设置AppFolder? I only see getAppFolder but How I can set ?? 我只看到getAppFolder但我怎么设置?

Thanks 谢谢

By design, GDAA supports only the FILE scope, ie it will find / list only folders / files created by the Android app. 根据设计, GDAA仅支持FILE范围,即它将仅查找/列出由Android应用程序创建的文件夹/文件。

There are 2 ways around it: 它有两种方法:

  1. Use one of the intents of the GDAA, basically letting the user pick the file / folder. 使用GDAA的一个意图 ,基本上让用户选择文件/文件夹。 That way it will become available to your app. 这样它将可用于您的应用程序。
  2. Use a different API, the REST Api, which supports the DRIVE scope, giving your app full set of files / folders. 使用不同的API, REST Api,它支持DRIVE范围,为您的应用程序提供全套文件/文件夹。

In case you want to study how the two APIs behave, I've put two different demos on the Github (the REST and the GDAA CRUD demo wrappers). 如果你想研究两个API的行为方式,我在Github( RESTGDAA CRUD演示包装器)上放了两个不同的演示。

The second part of your question does not have answer. 你问题的第二部分没有答案。 You don't set the app folder, you can only get it's DriveFolder id. 你没有设置app文件夹,你只能得到它的DriveFolder id。 You use it to create / retrieve objects. 您可以使用它来创建/检索对象。

  DriveFolder appFldr = Drive.DriveApi.getAppFolder(mGooleApiClient);
  appFldr.createFile(...);
  appFldr.createFolder(...);
  appFldr.listChildren(...);
  appFldr.queryChildren(...);

... and don't forget to add the SCOPE_APPFOLDER scope ...并且不要忘记添加SCOPE_APPFOLDER范围

Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM