Java WebアプリケーションがREST要求を使用するようにLinuxインスタンスを設定して実行しているAmazon EC2があります。問題は、このアプリケーションでGoogle Cloud Visionを使用して、ユーザーの写真の暴力/ヌードを認識しようとしていることです。私のターミナルでEC2へのアクセスGoogleアプリケーションの資格情報が設定されていないと見つかりません
が、私はマニュアルを参照し、次のコマンドによってGOOGLE_APPLICATION_CREDENTIALSを設定します。私は私のサーバーを再起動すると、と「エコーを実行しました:
export GOOGLE_APPLICATION_CREDENTIALS=<my_json_path.json>
ここに私の最初の問題が来ます$ GOOGLE_APPLICATION_CREDENTIALS '変数は削除されました。さて、私はそれをbash_profileとbashrcに設定しましたが、今は大丈夫です。
しかし、私は私の絵の大人と暴力のステータスを取得するには、上記のコードを消費し、自分のアプリケーションを実行したとき、私は次のエラーを得た:
java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. 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.
私のコードは以下の通りです:
コントローラ:
if(SafeSearchDetection.isSafe(user.getId())) {
if(UserDB.updateUserProfile(user)==false){
throw new SQLException("Failed to Update");
}
} else {
throw new IOException("Explicit Content");
}
SafeSearchDetection.isSafe(INT idUser):
String path = IMAGES_PATH + idUser + ".jpg";
try {
mAdultMedicalViolence = detectSafeSearch(path);
if(mAdultMedicalViolence.get(0) > 3)
return false;
else if(mAdultMedicalViolence.get(1) > 3)
return false;
else if(mAdultMedicalViolence.get(2) > 3)
return false;
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return true;
detectSafeSearch(文字列のパス):