问题描述
我在使用Google授权方面遇到了一些麻烦,而且以前从未使用过任何涉及Google凭证的过程".
I've been having some troubles with Google Authorization and I've never worked with any "Google credentials-involved" process before.
我的问题发生在创建凭证读取器之后(我认为这意味着我可以正确访问Google凭证的JSON文件),就在我从GoogleNetHTTPTransport
实例化新的受信任传输的行中.在那里,抛出异常错误:
My problem takes place after I've created the credential reader (which I assume means that I could access my Google credential's JSON file correctly), just in the line where I instantiate a new Trusted Transport from the GoogleNetHTTPTransport
. There, the Exception error throws:
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
为何参与此过程的正当而清晰的解释.
I've been investigating but couldn't still find a decent and clear explanation of how these Transports work or why the KeyStore
is involved in this process.
我的代码是AsyncTask
的一部分,我正在使用该代码从Google表格中获取数据,目前我正试图对其进行访问.在这里,我留下了 authorize()方法,该方法将为我检索一个Credential
并传递给我的SheetsService
.
My code is part of an AsyncTask
I'm using to fetch data from a Google Sheet, for which I'm currently trying to get access. Here I leave you authorize() method that will retrieve me a Credential
to pass to my 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的开发,我对了解其所有可能性非常感兴趣.我也对编码提出了任何建议.
Thanks in advance, I'm just starting with Google developing and I'm very interested in learning about all its possibilities. I also take any suggestions to my coding.
推荐答案
以下是帮助我解决此问题的答案 https://stackoverflow.com/a/39249969/8853293 您必须替换
Here is answer that helped me solve this issuehttps://stackoverflow.com/a/39249969/8853293You have to replace
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
使用
HTTP_TRANSPORT = new com.google.api.client.http.javanet.NetHttpTransport()
这篇关于尝试GoogleNetHTTPTransport时“未找到JKS"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!