Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android版Google Drive SDK:如果我知道文件夹标题,如何获取文件夹id_Java_Android_Google Drive Api_Google Drive Android Api - Fatal编程技术网

Java Android版Google Drive SDK:如果我知道文件夹标题,如何获取文件夹id

Java Android版Google Drive SDK:如果我知道文件夹标题,如何获取文件夹id,java,android,google-drive-api,google-drive-android-api,Java,Android,Google Drive Api,Google Drive Android Api,我需要将文件上传到谷歌硬盘上的一个文件夹,该文件夹以前是由其他用户创建的,我知道文件夹名称,如果我知道文件夹名称(标题),如何通过编程从android应用程序获取文件夹ID。您的帖子中有两个问题: 如何在其他用户创建的文件夹中上载文件 答:首先,您需要拥有该文件夹的写入权限,以便在该文件夹中插入一些内容。如果您知道文件夹的标题和文件以及目标文件夹,则可以使用CreateFileActivityBuilder类在文件夹中创建文件。还可以使用此类指定文件的初始元数据和内容 以下是代码和详细信息: 驱

我需要将文件上传到谷歌硬盘上的一个文件夹,该文件夹以前是由其他用户创建的,我知道文件夹名称,如果我知道文件夹名称(标题),如何通过编程从android应用程序获取文件夹ID。

您的帖子中有两个问题:

  • 如何在其他用户创建的文件夹中上载文件
  • 答:首先,您需要拥有该文件夹的写入权限,以便在该文件夹中插入一些内容。如果您知道文件夹的标题和文件以及目标文件夹,则可以使用CreateFileActivityBuilder类在文件夹中创建文件。还可以使用此类指定文件的初始元数据和内容

    以下是代码和详细信息:


    驱动器Android API目前仅支持每个文件的访问,称为文件范围。用户需要通过文件选择器选择文件夹,以便授权您的应用程序访问该文件夹

    我们希望能够在未来将驱动范围添加到Android API中,但在现阶段我无法共享时间表。如果您能在我们的网站上分享更多关于此功能用例的详细信息,那就太好了


    在此期间,您应该能够使用支持您的用例。

    正如Daniel指出的,您必须在您的用例中使用RESTAPI。更具体地说,这里有一种方法可以做到这一点:

    static com.google.api.services.drive.Drive mGOOSvc;
    
    /**************************************************************************
     * find file/folder in GOODrive
     * @param prnId   parent ID (optional), null searches full drive, "root" searches Drive root
     * @param titl    file/folder name (optional)
     * @param mime    file/folder mime type (optional)
     * @return        arraylist of found objects
     */
    static ArrayList<ContentValues> search(String prnId, String titl, String mime) {
      ArrayList<ContentValues> gfs = new ArrayList<>();
      if (mGOOSvc != null) try {
        // add query conditions, build query
        String qryClause = "'me' in owners and ";
        if (prnId != null) qryClause += "'" + prnId + "' in parents and ";
        if (titl != null) qryClause += "title = '" + titl + "' and ";
        if (mime != null) qryClause += "mimeType = '" + mime + "' and ";
        qryClause = qryClause.substring(0, qryClause.length() - " and ".length());
        Drive.Files.List qry = mGOOSvc.files().list().setQ(qryClause)
          .setFields("items(id,mimeType,labels/trashed,title),nextPageToken");
        String npTok = null;
        if (qry != null) do {
          FileList gLst = qry.execute();
          if (gLst != null) {
            for (File gFl : gLst.getItems()) {
              if (gFl.getLabels().getTrashed()) continue;
              gfs.add( UT.newCVs(gFl.getTitle(),gFl.getId()));
            }
            npTok = gLst.getNextPageToken();
            qry.setPageToken(npTok);
          }
        } while (npTok != null && npTok.length() > 0);
      } catch (Exception e) { /* handle the exceptions*/ }
      return gfs;
    }
    
    static com.google.api.services.drive.drive mGOOSvc;
    /**************************************************************************
    *在GOODrive中查找文件/文件夹
    *@param prnId parent ID(可选),null搜索完整驱动器,“root”搜索驱动器根
    *@param titl文件/文件夹名称(可选)
    *@param mime文件/文件夹mime类型(可选)
    *@return找到的对象的arraylist
    */
    静态ArrayList搜索(字符串prnId、字符串标题、字符串mime){
    ArrayList gfs=新的ArrayList();
    如果(mGOOSvc!=null),请尝试{
    //添加查询条件,生成查询
    字符串qryClause=“‘我’在所有者和”;
    如果(prnId!=null)qryClause+=“'”、“+prnId+”,则在父级和”;
    如果(titl!=null)q循环原因+=“title=”“+titl+””和“;
    如果(mime!=null)qrycause+=“mimeType=”“+mime+””和“;
    qrycause=qrycause.substring(0,qrycause.length()-“and”.length());
    Drive.Files.List qry=mGOOSvc.Files().List().setQ(qrcause)
    .设置字段(“项目(id、mimeType、标签/垃圾、标题),下一个GetOken”);
    字符串npTok=null;
    如果(qry!=null)do{
    FileList gLst=qry.execute();
    如果(gLst!=null){
    对于(文件gFl:gLst.getItems()){
    如果(gFl.getLabels().getRashed())继续;
    add(UT.newCVs(gFl.getTitle(),gFl.getId());
    }
    npTok=gLst.getNextPageToken();
    qry.setPageToken(npTok);
    }
    }while(npTok!=null&&npTok.length()>0);
    }catch(异常e){/*处理异常*/}
    返回gfs;
    }
    
    您所追求的是gFl.getId()。您仍然需要获得com.google.api.services.drive.drive mGOOSvc。有关完整的上下文,请参见此


    祝你好运

    谢谢,但我特别关心的是如何通过知道文件夹名称来获取文件夹ID。例如,应用程序的另一个用户在同一个google drive帐户上创建了一个包含今天日期(9月22日数据)的文件夹,我想将数据上传到该文件夹。我知道如何使用query搜索文件/文件夹,但是否仍然可以获得授权Google Drive帐户的folderID?
     private static DriveId sFolderId = DriveId.decodeFromString("DriveId:0B2EEtIjPUdX6MERsWlYxN3J6RU0");
    
    static com.google.api.services.drive.Drive mGOOSvc;
    
    /**************************************************************************
     * find file/folder in GOODrive
     * @param prnId   parent ID (optional), null searches full drive, "root" searches Drive root
     * @param titl    file/folder name (optional)
     * @param mime    file/folder mime type (optional)
     * @return        arraylist of found objects
     */
    static ArrayList<ContentValues> search(String prnId, String titl, String mime) {
      ArrayList<ContentValues> gfs = new ArrayList<>();
      if (mGOOSvc != null) try {
        // add query conditions, build query
        String qryClause = "'me' in owners and ";
        if (prnId != null) qryClause += "'" + prnId + "' in parents and ";
        if (titl != null) qryClause += "title = '" + titl + "' and ";
        if (mime != null) qryClause += "mimeType = '" + mime + "' and ";
        qryClause = qryClause.substring(0, qryClause.length() - " and ".length());
        Drive.Files.List qry = mGOOSvc.files().list().setQ(qryClause)
          .setFields("items(id,mimeType,labels/trashed,title),nextPageToken");
        String npTok = null;
        if (qry != null) do {
          FileList gLst = qry.execute();
          if (gLst != null) {
            for (File gFl : gLst.getItems()) {
              if (gFl.getLabels().getTrashed()) continue;
              gfs.add( UT.newCVs(gFl.getTitle(),gFl.getId()));
            }
            npTok = gLst.getNextPageToken();
            qry.setPageToken(npTok);
          }
        } while (npTok != null && npTok.length() > 0);
      } catch (Exception e) { /* handle the exceptions*/ }
      return gfs;
    }