Google drive API URL changes

2 views
Skip to first unread message

Pradeep Kr Kaushal via StackOverflow

unread,
May 3, 2016, 3:19:04 PM5/3/16
to google-appengin...@googlegroups.com

The application is running on production server which access https://www.googleapi.com through a proxy server. So how to set the url instead of https://www.googleapi.com to http://www.googleapi.com:443.

The sample code what currently is being used is

    File dataStoreDir = new File(resourceDir, credentials);

    JsonFactory jacksonFactory = JacksonFactory.getDefaultInstance();

    //List<String> scopes = Arrays.asList(DriveScopes.DRIVE);
    List<String> scopes = Arrays.asList("http://www.googleapis.com/auth/drive:443");

    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(dataStoreDir);


    String clientSecret = config.getClientSecret();

    InputStream in = new FileInputStream(new File(resourceDir, clientSecret));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jacksonFactory, new InputStreamReader(in));


    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    httpTransport, jacksonFactory, clientSecrets, scopes)
                    .setDataStoreFactory(dataStoreFactory)
                    .setAccessType("offline")
                    .setAuthorizationServerEncodedUrl("http://www.googleapis.com/auth/drive:443")
                    .build();
    Credential credential = new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize("user");

    logger.info("Credentials saved to " + dataStoreDir.getAbsolutePath());


    drive =  new Drive.Builder(
            httpTransport, jacksonFactory, credential)
            .setApplicationName(applicationName)
            .build();

How to change the url in above code? When I change the drive instance creation

drive =  new Drive.Builder(
                httpTransport, jacksonFactory, credential)
                .setApplicationName(applicationName).setRootUrl("http://www.googleapis.com:443/")
                .build();

Then it gives the error

    ERROR [2016-05-03 18:39:10,847] com.test.intranet.sao.GoogleDocSAO: Connection reset
! java.net.SocketException: Connection reset
! at java.net.SocketInputStream.read(SocketInputStream.java:209) ~[na:1.8.0_65]
! at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_65]
! at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_65]
! at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[na:1.8.0_65]
! at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[na:1.8.0_65]
! at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704) ~[na:1.8.0_65]
! at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647) ~[na:1.8.0_65]
! at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675) ~[na:1.8.0_65]
! at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1536) ~[na:1.8.0_65]
! at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441) ~[na:1.8.0_65]
! at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[na:1.8.0_65]
! at com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:37) ~[google-http-client-1.20.0.jar:1.20.0]
! at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94) ~[google-http-client-1.20.0.jar:1.20.0]
! at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:972) ~[google-http-client-1.20.0.jar:1.20.0]
! at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) ~[google-api-client-1.20.0.jar:1.20.0]
! at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) ~[google-api-client-1.20.0.jar:1.20.0]
! at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) ~[google-api-client-1.20.0.jar:1.20.0]


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/37011973/google-drive-api-url-changes
Reply all
Reply to author
Forward
0 new messages