<tfoot id='hsJ4V'></tfoot>

  • <small id='hsJ4V'></small><noframes id='hsJ4V'>

    • <bdo id='hsJ4V'></bdo><ul id='hsJ4V'></ul>
        <legend id='hsJ4V'><style id='hsJ4V'><dir id='hsJ4V'><q id='hsJ4V'></q></dir></style></legend>

        <i id='hsJ4V'><tr id='hsJ4V'><dt id='hsJ4V'><q id='hsJ4V'><span id='hsJ4V'><b id='hsJ4V'><form id='hsJ4V'><ins id='hsJ4V'></ins><ul id='hsJ4V'></ul><sub id='hsJ4V'></sub></form><legend id='hsJ4V'></legend><bdo id='hsJ4V'><pre id='hsJ4V'><center id='hsJ4V'></center></pre></bdo></b><th id='hsJ4V'></th></span></q></dt></tr></i><div id='hsJ4V'><tfoot id='hsJ4V'></tfoot><dl id='hsJ4V'><fieldset id='hsJ4V'></fieldset></dl></div>

      1. 如何使用 Google API 在团队云端硬盘中创建文件夹?

        时间:2023-07-14
        <tfoot id='8xIuJ'></tfoot>

        <small id='8xIuJ'></small><noframes id='8xIuJ'>

            <i id='8xIuJ'><tr id='8xIuJ'><dt id='8xIuJ'><q id='8xIuJ'><span id='8xIuJ'><b id='8xIuJ'><form id='8xIuJ'><ins id='8xIuJ'></ins><ul id='8xIuJ'></ul><sub id='8xIuJ'></sub></form><legend id='8xIuJ'></legend><bdo id='8xIuJ'><pre id='8xIuJ'><center id='8xIuJ'></center></pre></bdo></b><th id='8xIuJ'></th></span></q></dt></tr></i><div id='8xIuJ'><tfoot id='8xIuJ'></tfoot><dl id='8xIuJ'><fieldset id='8xIuJ'></fieldset></dl></div>
              • <legend id='8xIuJ'><style id='8xIuJ'><dir id='8xIuJ'><q id='8xIuJ'></q></dir></style></legend>

                  <tbody id='8xIuJ'></tbody>
                • <bdo id='8xIuJ'></bdo><ul id='8xIuJ'></ul>

                  本文介绍了如何使用 Google API 在团队云端硬盘中创建文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在努力使用 Google API PHP 客户端库在团队云端硬盘中创建文件夹.

                  I'm struggling to create a folder within a Team Drive using the Google API PHP Client Library.

                  我正在使用服务帐户并冒充作为团队云端硬盘成员的用户(我自己)并且可以列出云端硬盘的内容.但是,当我创建文件夹时,它总是在我的云端硬盘"中创建,而不是在指定的团队云端硬盘中创建.

                  I am using a service account and impersonating a user (myself) who is a member of the Team Drive and can list the contents of the drive. However, when I create a folder it always creates it in 'My Drive' rather than the Team Drive specified.

                  尝试 1

                  $client = new Google_Client();
                  $client->useApplicationDefaultCredentials();
                  $client->addScope("https://www.googleapis.com/auth/drive");
                  $client->setSubject('user@mydomain.com');
                  
                  $service = new Google_Service_Drive($client);
                  
                  $folderId = '0AIuzzEYPQu9CUk9PVA';
                  $fileMetadata = new Google_Service_Drive_DriveFile(array(
                      'name' => 'New Test Folder',
                      'mimeType' => 'application/vnd.google-apps.folder',
                      'supportsAllDrives' => true,
                      'parents' => ['0AIuzzEYPQu9CUk9PVA']
                  ));
                  

                  尝试 2

                  $fileMetadata = new Google_Service_Drive_DriveFile(array(
                      'name' => 'New Test Folder',
                      'mimeType' => 'application/vnd.google-apps.folder',
                      'supportsAllDrives' => true,
                      'driveId' => '0AIuzzEYPQu9CUk9PVA'
                  ));
                  

                  更新尝试 3

                  $fileMetadata = new Google_Service_Drive_DriveFile(array(
                      'name' => 'Hello 123',
                      'supportsAllDrives' => true,
                      'mimeType' => 'application/vnd.google-apps.folder',
                      'parents' => ['0AIuzzEYPQu9CUk9PVA']
                  ));
                  
                  $file = $service->files->create($fileMetadata, array(
                        'fields' => 'id'));
                      printf("Folder ID: %s
                  ", $file->id);
                  

                  尝试 3 出现此错误:致命错误:未捕获的 Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "File not found: 0AIuzzEYPQu9CUk9PVA.", "locationType": "参数", "位置": "fileId" } ]

                  Attempt 3 gives this error: Fatal error: Uncaught Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "File not found: 0AIuzzEYPQu9CUk9PVA.", "locationType": "parameter", "location": "fileId" } ]

                  我已阅读有关团队的所有(有限)文档驱动器和 API 并了解团队驱动器中的文件夹/文件只能有一个父级(团队驱动器的 ID),因此我尝试将父级的变体作为数组和字符串.

                  I have read all the (limited) documentation regarding Team Drive and the API and understand that a folder/file within a Team Drive can only have one parent (The Team Drive's ID) so I have tried variations of the parent as an array and string.

                  文件夹创建正确,只是位置错误.

                  The folder is created correctly, just in the wrong place.

                  推荐答案

                  关于如何在 Teamdrives 中创建文件夹的文档不是很清楚,但这是您需要注意的两件事:

                  The documentation is not very clear on how to handle the creation of folders inside Teamdrives but this are the two things you need to take note of:

                  1.'supportsAllDrives' =>true, 是可选参数的一部分,而不是文件元数据的一部分.2. parentdriveId 都应该包含在元数据中

                  1.'supportsAllDrives' => true, is part of the optional parameters and not part of the file metadata. 2. Both the parent and the driveId should be included as part of the metadata

                  所以这是一个关于如何实现这一点的示例:

                  So here is an example on how to achieve this:

                  $service = new Google_Service_Drive($client);
                  $parent = "0AA3C8xRqwerLglUk9PVA"; //Teamdrive ID
                  
                  //Create new folder
                  $file = new Google_Service_Drive_DriveFile(array(
                      'name' => 'Test Folder',
                      'mimeType' => 'application/vnd.google-apps.folder',    
                      'driveId' => $parent,
                      'parents' => array($parent)
                  ));
                  
                  $optParams = array( 
                      'fields' => 'id', 
                      'supportsAllDrives' => true,
                  );
                  
                  $createdFile = $service->files->create($file, $optParams);
                  print "Created Folder: ".$createdFile->id;
                  

                  请注意:您需要 2.1.3 或更高版本的客户端库.

                  Please Note: You will need the client library version 2.1.3 or greater.

                  这篇关于如何使用 Google API 在团队云端硬盘中创建文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:谷歌日历 API - PHP 下一篇:将文件提交到 Google Drive

                  相关文章

                    • <bdo id='fRWzi'></bdo><ul id='fRWzi'></ul>

                  1. <i id='fRWzi'><tr id='fRWzi'><dt id='fRWzi'><q id='fRWzi'><span id='fRWzi'><b id='fRWzi'><form id='fRWzi'><ins id='fRWzi'></ins><ul id='fRWzi'></ul><sub id='fRWzi'></sub></form><legend id='fRWzi'></legend><bdo id='fRWzi'><pre id='fRWzi'><center id='fRWzi'></center></pre></bdo></b><th id='fRWzi'></th></span></q></dt></tr></i><div id='fRWzi'><tfoot id='fRWzi'></tfoot><dl id='fRWzi'><fieldset id='fRWzi'></fieldset></dl></div>

                    <tfoot id='fRWzi'></tfoot>

                      <legend id='fRWzi'><style id='fRWzi'><dir id='fRWzi'><q id='fRWzi'></q></dir></style></legend>

                      <small id='fRWzi'></small><noframes id='fRWzi'>