有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java希望使用嵌入式凭据访问Google云数据存储

我有一个Java应用程序,我想在Google云数据存储中存储用户数据。入门教程中给出的步骤提到将凭据添加到环境中,但对于最终用户来说,这似乎不是一个好的解决方案。我希望能够从一组嵌入式凭据(一个文件或一组字符串)生成到数据库的连接。这样,我就可以在用户继续正常使用应用程序的同时,在后台管理凭据

是否有一种方法可以创建DatastoreService对象并手动传递凭据,而不是使用。getCredentialsFromEnv()方法


共 (1) 个答案

  1. # 1 楼答案

    是的,你可以用.getServiceAccountCredential

      /**
       * Constructs credentials for the given account and key.
       *
       * @param account the account to use.
       * @param privateKeyFile the file name from which to get the private key.
       * @return valid credentials or {@code null}
       */
      public static Credential getServiceAccountCredential(String account, String privateKeyFile) {
        ...
      }