java eclipse google cloud platform 執行時跳出以下錯誤訊息
Exception in thread "main" java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute
该回答引用GPTᴼᴾᴱᴺᴬᴵ
這個錯誤通常發生在你嘗試在本地開發環境中使用 Google Cloud Platform API 時。該錯誤信息表明該應用程序正在尋找 Google Cloud Platform 的默認憑證,但找不到它們。
要解決此問題,可以按照以下步驟來配置 Google Cloud Platform 憑證:
在 Java 中,你可以在啟動應用程序時使用 GOOGLE_APPLICATION_CREDENTIALS 環境變量來設置 JSON 憑證文件的路徑。例如,在你的 Eclipse 項目中,可以使用以下代碼行設置環境變量:
System.setProperty("GOOGLE_APPLICATION_CREDENTIALS", "/path/to/your/json/credentials.json");
這樣,你的應用程序應該可以正確訪問 Google Cloud Platform API 並運行了。