使用服务帐户从Java中在Google云端硬盘G Suite中创建文件:403权限不足

问题描述

我正在尝试在Google云端硬盘文件夹中创建文件。

从文件夹读取即可。我已经在使用不同的服务帐户读取不同应用程序中的文件。

我与生成的服务帐户电子邮件共享了G Suite Drive文件夹,并授予了编辑者访问权限(读取,写入,编辑)。

我试图从Java Springboot应用程序复制一个现有文件(但还要从头开始创建一个空文件)。

public class TemplateDocumentManager {

    @Value("${printing.template.id}")
    private String baseTemplateFileId;

    @Autowired
    private Drive driveService;

    public void createNewContractFromEmptyTemplate() throws IOException {
        File templateFile = getDriveFiles().get(baseTemplateFileId).execute();

        File newFileInstance = getDriveFiles()
                .copy(baseTemplateFileId,templateFile)
                .setSupportsAllDrives(true)
                .execute();
        log.error("Id of newly created file is: {}",newFileInstance.getId());
    }

    protected Drive.Files getDriveFiles() {
        return driveService.files();
    }
}

注入了@Autowired批注的google驱动器服务正常运行。它的创建过程如下:

@Configuration
public class DriveService {

    public static final String APPLICATION_NAME = "appname";

    @Autowired
    GoogleCredential googleCredential;

    @Bean("driveService")
    public Drive createDriveService() throws GeneralSecurityException,IOException {
        return new Drive.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),googleCredential)
                .setApplicationName(APPLICATION_NAME)
                .build();
    }

    ...
}

关于什么服务帐户需要能够在G Suite Drive文件夹上写入的任何想法?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)