我想使用谷歌云云自然語言的API。谷歌云云自然語言API
我已經有了谷歌雲中運行的帳戶。 我支持雲自然語言API服務和生成服務帳戶密鑰和下載到本地。
我火腿使用我使用的Eclipse爲IDE上的Mac
護目鏡默認程序
LanguageServiceClient language = LanguageServiceClient.create();
// The text to analyze
String text = "My stay at this hotel was not so good";
Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();
// Detects the sentiment of the text
Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();
System.out.printf("Text: %s%n", text);
System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude());
當我運行應用程序,我得到了錯誤
java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute E
ngine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs
/application-default-credentials for more information.
我什至增加GOOGLE_APPLICATION_CREDENTIALS在終端出口和使用「printenv」它顯示了這樣的
GOOGLE_APPLICATION_CREDENTIALS=/Users/temp/Downloads/Sentiment-0e556940c1d8.json
的路徑,但它依然不能與某些命中和試驗方法,我發現在Eclipse中我們可以配置運行工作。
在那裏,我已經添加的環境變量後,當我運行程序,它工作正常。現在
我的問題是我實現J2EE項目中的代碼和EAR文件中Wildfly部署。 我再次收到同樣的錯誤。現在我不知道在蜻蜓或哪裏設置enviromnet變量的位置?