【问题标题】:'JKS not found' when trying GoogleNetHTTPTransport尝试 GoogleNetHTTPTransport 时出现“未找到 JKS”
【发布时间】:2018-11-03 22:01:23
【问题描述】:

我在使用 Google 授权时遇到了一些问题,而且我以前从未使用过任何“涉及 Google 凭据”的流程。

我的问题发生在我创建凭据读取器之后(我假设这意味着我可以正确访问我的 Google 凭据的 JSON 文件),就在我从 GoogleNetHTTPTransport 实例化新的受信任传输的行中。在那里,抛出异常错误:

W/System.err: java.security.KeyStoreException: JKS not found
    at java.security.KeyStore.getInstance(KeyStore.java:649)
    at com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
    at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:74)
    at com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
    at com.example.juans.hasapp.getDataFromSheet.authorize(getDataFromSheet.java:70)

我一直在调查,但仍然找不到关于这些传输如何工作或为什么KeyStore 参与此过程的正确而清晰的解释。

我的代码是AsyncTask 的一部分,我用于从 Google 表格中获取数据,我目前正在尝试访问该表格。在这里我留给你 authorize() 方法,该方法将检索我一个 Credential 并传递给我的 SheetsService

private Credential authorize(Context context) {
    Resources resources = context.getResources();
    InputStream jsonInput = resources.openRawResource(R.raw.credential_info);
    Reader credentialReader = null;
    try {
        credentialReader = new InputStreamReader(jsonInput);
        Log.v("GoogleAut", "credential reader created");
    } catch (NullPointerException n){
        Log.v("ERROR GoogleAut", "filePath came out empty, no info provided");
    }

    GoogleClientSecrets clientSecrets = null;
    try {
        clientSecrets = GoogleClientSecrets
                .load(JacksonFactory.getDefaultInstance(),credentialReader);
    } catch (IOException e) {
        e.printStackTrace();
        Log.v("ERROR GoogleAut","IOException error occurred");
    }

    List<String> scopes = Arrays.asList(SheetsScopes.SPREADSHEETS);

    GoogleAuthorizationCodeFlow flow = null;
    try {
        flow = new GoogleAuthorizationCodeFlow
                .Builder(GoogleNetHttpTransport.newTrustedTransport()
                , JacksonFactory.getDefaultInstance()
                ,clientSecrets
                ,scopes)
                .setDataStoreFactory(new MemoryDataStoreFactory())
                .setAccessType("offline")
                .build();
    } catch (IOException e) {
        e.printStackTrace();
        Log.v("ERROR GoogleAut","IOException error occurred");
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
        Log.v("ERROR GoogleAut","GeneralSecurityException error occurred");
    }

    try {
        return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
                .authorize("user");
    } catch (Exception e) {
        e.printStackTrace();
        Log.v("ERROR GoogleAut", "Unidentified error");
    }
    return null;
}

提前致谢,我刚开始开发 Google,我对了解它的所有可能性非常感兴趣。我也会对我的编码提出任何建议。

【问题讨论】:

标签: android keystore credentials google-oauth jks


【解决方案1】:

这是帮助我解决此问题的答案 https://stackoverflow.com/a/39249969/8853293 你必须更换

HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

HTTP_TRANSPORT = new com.google.api.client.http.javanet.NetHttpTransport()

【讨论】:

    猜你喜欢
    • 2017-02-28
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 2022-06-22
    • 2021-09-27
    • 2019-03-01
    • 2012-05-08
    • 1970-01-01
    相关资源
    最近更新 更多