텍스트를 한 언어에서 다른 언어로 번역해야합니다. Google 번역 API을 사용하고 있습니다. 그러나 인증을받을 수 없습니다. 코드를 통해 인증 정보를 제공하고 싶습니다. 전역 변수를 사용하여 자동으로 인증하고 싶지 않습니다. (여전히 좋은 생각입니다.)인증 할 수 없음 : JSON 입력을 찾을 수 없습니다.
API 키를 설정하는 간단한 방법이 있지만 간단한 방법으로 자격 증명을 지정하는 방법이 없습니다. 그래서 서비스 키를 만들 때 얻은 JSON으로 인증하기로 결정했습니다. 스칼라 코드에서 다음
{
"type": "service_account",
"project_id": "toto",
"private_key_id": "tata",
"private_key": "titi",
"client_email": "tete",
"client_id": "tutu",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/toto"
}
:
val cred = GoogleCredentials.fromStream(JSON_AUTHENTICATION_INPUT_STREAM)
TranslateOptions.newBuilder().setCredentials(cred)
그리고, 물론, 나는 다음과 같은 오류 얻을 :
java.lang.IllegalArgumentException: no JSON input found
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:125)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:49)
at com.google.api.client.json.JsonParser.startParsing(JsonParser.java:223)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:380)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:355)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream(GoogleCredential.java:250)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream(GoogleCredential.java:226)
at services.TranslatorBaseImpl.<init>(Translator.scala:58)
그래서 무엇을? JSON 인증이 작동하지 않습니까? 코드를 통해 어떻게 인증 할 수 있습니까?
공식 문서에서 몇 시간 동안 수색했으나 그런 고급 ... 케이스에는 쓸모가 없습니다. 귀하의 답변
감사합니다, 키스