Google api 谷歌云自然语言API
我正在尝试使用谷歌云自然语言API。 我已经有谷歌云运行帐户。 我启用了云自然语言API服务,生成了服务帐户密钥并在本地下载 我使用了Goggle默认程序Google api 谷歌云自然语言API,google-api,wildfly,Google Api,Wildfly,我正在尝试使用谷歌云自然语言API。 我已经有谷歌云运行帐户。 我启用了云自然语言API服务,生成了服务帐户密钥并在本地下载 我使用了Goggle默认程序 LanguageServiceClient language = LanguageServiceClient.create(); // The text to analyze String text = "My stay at this hotel was not so good"; Document doc = Document.newB
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());
我正在使用Eclipse作为Mac上的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\u应用程序\u凭据作为导出,并使用“printenv”显示如下路径
GOOGLE_APPLICATION_CREDENTIALS=/Users/temp/Downloads/Sentiment-0e556940c1d8.json
尽管如此,它仍然不能使用一些点击和试用的方法,我发现在eclipse中我们可以配置run
在那个里,我添加了环境变量,在那个之后,当我运行程序时,它工作得很好
现在我的问题是,我正在J2EE项目中实现该代码,而ear文件将部署在Wildfly中。
我又犯了同样的错误。现在我不知道在Wildfly中在哪里设置enviromnet变量,或者在哪里???最后我找到了一种在Wildfly中设置GOOGLE应用程序凭据作为环境变量的方法
- 双击内部的服务器打开Wildfly服务器设置 服务器选项卡
- 单击“打开启动配置”
- 移动到“环境”选项卡并添加新变量作为键值对
就这样。你可以走了 最后,我找到了一种在Wildfly中将GOOGLE_应用程序_凭据设置为环境变量的方法
- 双击内部的服务器打开Wildfly服务器设置 服务器选项卡
- 单击“打开启动配置”
- 移动到“环境”选项卡并添加新变量作为键值对