且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javax.net.ssl.sslpeerunverifiedexception 没有对等证书 LifelogApi 中的错误

更新时间:2023-12-03 14:07:34

我正在使用 google-oauth-client,我可以在 Android 5.x 上使用这个初始化为

I'm using google-oauth-client, I was able to use on Android 5.x with this initialization for

导入 com.google.api.client.http.HttpTransport;

private void initializeSocketFactory() {
    if (Build.VERSION.SDK_INT >= 23) {
        HTTP_TRANSPORT = new NetHttpTransport();
    } else {
        //Android 5 and bellow needs this SSL Socket factory initialization
        try {
            SSLContext sslContext = SSLContext.getInstance("TLSv1");
            sslContext.init(null, null, null);
            SSLSocketFactory socketFactory = sslContext.getSocketFactory();
            NetHttpTransport.Builder netTransportBuilder = new NetHttpTransport.Builder();
            netTransportBuilder.setSslSocketFactory(socketFactory);
            HTTP_TRANSPORT = netTransportBuilder.build();
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            Log.e(LOG_TAG, "Problem instantiating cipher for ssl socket", e);
        }
    }

}

你使用 HTTP_TRANSPORT 来实例化:

导入 com.google.api.client.auth.oauth2.AuthorizationCodeFlow;