【发布时间】: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