【问题标题】:Google drive API URL changesGoogle 云端硬盘 API 网址更改
【发布时间】:2016-05-03 18:42:05
【问题描述】:

应用程序在生产服务器上运行,通过代理服务器访问https://www.googleapi.com。那么如何将url而不是https://www.googleapi.com设置为http://www.googleapi.com:443

目前使用的示例代码是

    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();

如何更改上述代码中的网址? 当我更改drive 实例创建时

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

然后它给出错误

    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]

【问题讨论】:

    标签: java google-drive-api


    【解决方案1】:

    Google Drive 可以通过代理服务器工作,方法是将所需的连接应用到Google Drive firewall and proxy setting 中列出的以下主机和端口。

    但是,请注意,Google 目前不支持对其地址的连接进行身份验证。您必须绕过 Google Apps 管理员帮助页面中给定地址的身份验证,才能允许 Google 通过您的代理工作。

    How to configure your proxy server to work with Google Drive 中给出了可能的代理服务器配置。

    【讨论】:

      猜你喜欢
      • 2016-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多