谷歌云云自然语言API

问题描述:

我想使用谷歌云云自然语言的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变量的位置?

最后,我找到了一种方法来设置GOOGLE_APPLICATION_CREDENTIALS作为环境变量中Wildfly

  1. 如果您是通过Eclipse中通过双击运行服务器

    • 打开Wildfly服务器设置一下您的服务器里面 服务器选项卡
    • 点击“打开启动配置”
    • 移动到 “环境” 选项卡并添加新的变量作为键值

    例如

    GOOGLE_APPLICATION_CREDENTIALS /Users/temp/Downloads/Sentiment-0e556940c1d8.json

  2. 如果您正在运行使用终端的服务器

    默认情况下,Wildfly会在独立内部寻找其他设置.conf文件。

    刚才打开野蝇/ bin/standalone。CONF文件,并添加以下行

    GOOGLE_APPLICATION_CREDENTIALS = /用户/温度/下载/情感0e556940c1d8.json

那它。你很好走.....