Skip to content

Exception: API Key and the authentication credential are from different projects #1405

@gguuss

Description

@gguuss

If you have multiple sets of valid credentials configured in your Java environment, the Cloud library will not resolve between the two.

Repro steps

  1. Configure client library for API key: export GOOGLE_API_KEY=SOME_VALID_DEVELOPER_KEY
  2. Configure client library for valid credentials from separate project: export GOOGLE_APPLICATION_CREDENTIALS=./creds.json
  3. Run java sample, e.g. from github.com/GoogleCloudPlatform/java-docs-samples/translate...
mvn clean compile assembly:single
JAR_FILE=target/translate-1.0-jar-with-dependencies.jar
INPUT="A quick brown fox jumped over a lazy dog."
SOURCE_LANG="en"
TARGET_LANG="fr"
java -jar $JAR_FILE translate "$INPUT" $SOURCE_LANG $TARGET_LANG

Expected outcome

Client library warns developer but uses an access token from the service account.

Actual outcome

Client library fails, throwing exception and crashing app.

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "The API Key and the authentication credential are from different projects.",
    "reason" : "badRequest"
  } ],
  "message" : "The API Key and the authentication credential are from different projects.",
  "status" : "INVALID_ARGUMENT"
}

Metadata

Metadata

Labels

api: translationIssues related to the Cloud Translation API API.authtype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions