简体   繁体   English

错误:使用 Java => java.net.UnknownHostException 连接 Google Cloud Storage 时:oauth2.googleapis.com

[英]Error: while connecting Google Cloud Storage using Java => java.net.UnknownHostException: oauth2.googleapis.com

While connecting to Google Cloud Storage using Java libraries, We are getting below exception :使用 Java 库连接到 Google Cloud Storage 时,我们遇到以下异常:

  1. Caused by: java.net.UnknownHostException: oauth2.googleapis.com引起:java.net.UnknownHostException:oauth2.googleapis.com
  2. Caused by: java.io.IOException: Error getting access token for service account: oauth2.googleapis.com引起:java.io.IOException:获取服务帐户的访问令牌时出错:oauth2.googleapis.com

We have created the Google Cloud Storage service account, Project and downloaded JSON file also.我们还创建了 Google Cloud Storage 服务帐户、项目并下载了 JSON 文件。

Below is the code snippet :下面是代码片段:

GoogleCredentials googleCredentails = 
            ServiceAccountCredentials.fromStream(new FileInputStream("D:\\Naresh\\Projects\\GoogleCloudStorage\\delta-trees-236311-ae7c1cfcda68.json"));

Storage googleStorageService = StorageOptions.newBuilder().setCredentials(googleCredentails)
            .setProjectId("delta-trees-236311")
            .build().getService();

String googleBucketName = "ewf-ocr-poc";
File f = new File("D:\\Naresh\\Projects\\GoogleCloudStorage\\EWFDocumentThroughJava.txt");
byte[] readFileToByteArray = readFileToByteArray(f);
String fileName = f.getName();
InputStream fis = new FileInputStream(f);        
googleStorageService.create(BlobInfo.newBuilder(googleBucketName, fileName).build(),
            readFileToByteArray);

It could be the internet pemission. 这可能是互联网的要求。

try: Android studio: <uses-permission android:name="android.permission.INTERNET" /> On Android Manifest 尝试:Android Studio:在Android Manifest上<uses-permission android:name="android.permission.INTERNET" />

Xamarin: Xamarin:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
         <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

On Android Manifest 在Android清单上

Looks like you need to add your https proxy in the java app to make your connection to gcp host work.看起来您需要在 java 应用程序中添加 https 代理才能使您与 gcp 主机的连接正常工作。 You can add is using below system properties:您可以使用以下系统属性添加:

    System.setProperty("https.proxyHost", yourProxyHost);
    System.setProperty("https.proxyPort", yourProxyPort);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.net.UnknownHostException:googleapis - java.net.UnknownHostException: googleapis 的java.net.UnknownHostException:www.google.com - java.net.UnknownHostException:www.google.com 的java.net.UnknownHostException - java.net.UnknownHostException Java测试用例的Cloud Speech API示例引发异常:原因:java.net.UnknownHostException:accounts.google.com - Cloud Speech API samples for Java test case throws exception: Caused by: java.net.UnknownHostException: accounts.google.com Jenkins java.net.UnknownHostException错误 - Jenkins java.net.UnknownHostException Error 如何在使用 Spring Boot 和 Eureka Server 时修复错误 java.net.UnknownHostException? - How to fix the error java.net.UnknownHostException while using Spring Boot and Eureka Server? java.net.UnknownHostException:&lt; <hostname> &gt;:未知错误 - java.net.UnknownHostException: <<hostname>> : unknown error 使用AsyncHttpClient的java.net.UnknownHostException - java.net.UnknownHostException using AsyncHttpClient java.net.UnknownHostException无法解析主机“accounts.google.com”:在bigquery中插入行时没有与主机名关联的地址 - java.net.UnknownHostException Unable to resolve host “accounts.google.com”: No address associated with hostname while inserting rows in bigquery java.net.UnknownHostException-Jsoup - java.net.UnknownHostException - Jsoup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM