Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

android - 'JKS not found' when trying GoogleNetHTTPTransport

I've been having some troubles with Google Authorization and I've never worked with any "Google credentials-involved" process before.

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)

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.

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;
}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is answer that helped me solve this issue https://stackoverflow.com/a/39249969/8853293 You have to replace

HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

with

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...