gpt4 book ai didi

android - 尝试 GoogleNetHTTPTransport 时“未找到 JKS”

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:36 34 4
gpt4 key购买 nike

我在 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 进行开发,我非常有兴趣了解它的所有可能性。我也会采纳对我的编码的任何建议。

最佳答案

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

HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

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

关于android - 尝试 GoogleNetHTTPTransport 时“未找到 JKS”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50513348/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com