【发布时间】:2018-03-06 16:33:10
【问题描述】:
我正在尝试使用 Google Cloud CLOUD NATURAL LANGUAGE API。
我已经有 Google 云运行帐户。 我启用了 CLOUD NATURAL LANGUAGE API 服务并生成了服务帐户密钥并在本地下载。
我习惯使用 Goggle 默认程序
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());
我在 Mac 上使用 Eclipse 作为 IDE
当我运行应用程序时出现错误
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 中。 我再次遇到同样的错误。现在我不知道在 Wildfly 中在哪里设置环境变量或在哪里???
【问题讨论】:
标签: google-api wildfly