如何在我的 java 应用程序中硬编码 Google OAuth 的 client_id 和 client_secret?

How can I hard-code client_id and client_secret of Google OAuth's in my java application?

我正在使用 java (https://developers.google.com/drive/v2/web/quickstart/java) 跟随 Google 驱动器的 API,并且有这行代码读取 .json 文件在我的项目目录中(我将其复制到那里),其中包含 client_id 和 client_secret。

    // Load client secrets.
    InputStream in = GoogleDrive.class.getResourceAsStream("client_id.json");
    this.clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();

我制作了一个 GoogleDrive.java class 让登录、上传等更容易。

如何在 .json 文件中对信息进行硬编码并将其 google "load" 保存到 clientsecrets,以便我可以在其他应用程序中使用此 class以及。我是 REST 的新手,所以我将不胜感激。

谢谢大家

找到答案,用这个方法(好吧,同样的方法,不同的签名)就可以了:)

public GoogleAuthorizationCodeFlow.Builder(HttpTransport transport,
                               JsonFactory jsonFactory,
                               String clientId,
                               String clientSecret,
                               Collection<String> scopes)