方案是:在https://console.developers.google.com/apis/credentials中创建OAuth 2.0客户端,我想从G Suite Business中的用户Google Drive(用户空间)中选择一些文件,然后将 copy 选择到 another owner 的Team Drive中的某个文件夹,然后选择 change the owner 最近复制的文件 .

最后一个操作导致找不到文件 error . 即使出现此错误,文件也会被复制文件并且 ID 响应告诉我它不存在 . 代码和堆栈如下:

const google = require('googleapis'); // https://github.com/google/google-api-nodejs-client
const oauth2Client = new OAuth2('client_id', 'client_secret', 'redirect_url');

oauth2Client.setCredentials({'access_token': '' ,'token_type': '','expiry_date': ''});

const sourceFileId = '';

const googleDrive = google.drive({
    version: 'v3',
    auth: oauth2Client
});

googleDrive.permissions.create({
    fileId: sourceFileId,
    resource: {
        role: 'reader',
        type: 'domain',
        domain: 'example.com',
    }
}, (error, permissionResponse) => {

    if (error) {

        console.log(error);

    } else {

        googleDrive.files.copy({
            fileId: sourceFileId,
            supportsTeamDrives: true,
            ignoreDefaultVisibility: true,
            resource: {
                description: 'Copy of a file from user to store in Team Driver',
                parents: ['_driveteam_folder_id_']
            }
        }, (copyError, copyResponse) => {

            if (copyError) {

                console.log(copyError);

            } else {

                console.log(copyResponse, copyResponse.id);

                // Even with this timeout the error occurrs
                // 1elLwBg0urdz5z23_83tjpDSBt7YxD1c8 is the copyResponse.id show in the error below
                setTimeout(() => {

                    googleDrive.permissions.create({
                        fileId: copyResponse.id,
                        transferOwnership: true,
                        resource: {
                            role: 'owner',
                            type: 'user',
                            emailAddress: 'someone@example.com'
                        }
                    }, (ownerPermissionError, ownerPermissionResponse) => {

                        if (ownerPermissionError) {

                            console.log(ownerPermissionError);

                        } else {

                            console.log({permissionResponse, copyResponse, ownerPermissionResponse});   

                        }

                    });

                }, 10000);

            }

        });

    }

});

{错误:找不到文件:1elLwBg0urdz5z23_83tjpDSBt7YxD1c8 . 在request._callback(googleapis \ node_modules \ google-auth-library \ lib \ transporters.js:85:15,在Request.self.callback(node_modules \ request \ request.js:186:22),在emitTwo(events.js: 106:13)Request.emit(events.js:191:7)在Request.emit(events.js:96:13)处的Request.emit(events_modules \ request \ _js:11:10)处.js:188:7)在IncomingMessage . (node_modules \ request \ request.js:1085:12)atcomingMessage.g(events.js:292:16)在emitNone(events.js:91:20)代码:404 ,错误:[{domain:'global',reason:'notFound',message:'找不到文件:1elLwBg0urdz5z23_83tjpDSBt7YxD1c8 . ',locationType:'parameter',location:'fileId'}]}