1
votes

I've followed the Google Cloud AutoML API quickstart of requesting api by using

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/projects/kintsugi-415310213303/locations/us-central1/models/TCN1592956918625708154:predict \
  -d '{
        "payload" : {
          "textSnippet": {
               "content": "YOUR TEXT HERE",
                "mime_type": "text/plain"
           },
        }
      }'

and following link, but I got this error

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. Se
e https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

I referred to Request had invalid authentication credentials. Expected OAuth 2 access token error in cloud speech api, and tried creating another access token with application-default login and got the below error:

{
  "error": {
    "code": 403,
    "message": "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by
 the automl.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how
 to use them in your application, see https://cloud.google.com/docs/authentication/.",
    "status": "PERMISSION_DENIED"
  }
}

I've also enabled permissions similar to this: https://github.com/googleapis/google-cloud-php/issues/1722 (AutoML Admin, AutoML Service Agent, AutoML Editor)

I'm the owner/admin of the project. It seems like the tokens are expiring and I may need to implement this server-side.

What should I do now?

Thanks in advance!

1
please include your authorization code.DaImTo
@DalmTo added, owner/admingrehce

1 Answers

3
votes

Realized I pointed to the wrong json file, re-generated the key (https://cloud.google.com/video-intelligence/docs/common/auth) and dragged/dropped the path directly into the terminal and was able to generate local results.

$ export GOOGLE_APPLICATION_CREDENTIALS=[json path]