【问题标题】:Set the default language of Google document while file creation with Google DRIVE API使用 Google DRIVE API 创建文件时设置 Google 文档的默认语言
【发布时间】:2017-04-06 21:13:50
【问题描述】:

我可以在 Google Drive 上创建文件,并且在使用 drive.google.com 时会自动为我设置语言。

但我在通过我的应用程序使用 Google Drive API 创建文件时遇到问题。(google-api-services-drive-v2-rev192-1.20.0.jar)

未设置文档的默认语言。 这会导致语音输入呈灰色显示。

这是我在应用程序中创建文件的方式:

    public static File createFile(Car car) {
    System.out.println("CREATING FILE");
    try {

        File body = new File();
        body.setTitle("Document for " + car.getCar_name()
                + ".docx");

        body.setMimeType(GOOGLE_DOCOCUMENT_MIME_TYPE);
        body.setEditable(true);
        

       
        Permission ownership = getOwnerShipPermission();
        Permission unlockedFile = getUnlockedFilePermission();
        java.io.File fileContent = null;
        fileContent = CarServiceReportTemplateFactory.createCarServiceReportTemplateFile(car);
        
        FileContent mediaContent = new FileContent(MS_WORD_DOCUMENT_MIME_TYPE, fileContent);
        File file = driveservice.files().insert(body, mediaContent).execute();
        String fildid = file.getId();
        driveservice.permissions().insert(fildid, unlockedFile).execute();
        fileContent.delete();
        return file;
        
    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
} 

我确实查看了the drive api file category,但找不到与设置默认语言相关的任何内容。

有趣的是,当我执行"Try it" simulator 时,生成的文件似乎默认设置了语言。 但是,当我在我的应用程序中尝试它时,默认情况下没有设置语言......因此语音输入显示为灰色。 这是我尝试过的:

  String timedTextLanguage = "English (United Kingdom)";
           
  File file = driveservice.files().insert(body, mediaContent).setTimedTextLanguage(timedTextLanguage).execute();

【问题讨论】:

  • 我注意到驱动客户端 jar 文件有一个更新的版本。会不会是这个?
  • 如果您检查 Google Drive API 的 v2 版本。可以更改文件语言的唯一选项是使用Files: insert 方法,该方法有一个可选参数timedTextLanguage 来设置文本的语言。如果它可以帮助您,请尝试此参数。更多信息,请查看相关SO question
  • 您好,Kendi,感谢您的帮助。我确实尝试了 timedTextlanguage,但没有运气。我基本上可以将“English”作为字符串参数传递吗?
  • 我尝试将 en-GB、English、english、en 作为参数传递,但我仍然遇到问题。

标签: java google-drive-api google-docs-api google-api-java-client


【解决方案1】:

这是导致这些问题的 Microsoft Word 文档。 但是我仍然不知道为什么在上传到 Google Drive 时没有设置语言。

【讨论】:

    猜你喜欢
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 2016-07-22
    相关资源
    最近更新 更多