[英]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 时,我们遇到以下异常:
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.