Google Cloud Translation API The request is missing a valid API key

前端 未结 3 1676
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 07:29

I\'m trying to use the Google Cloud Translation API in my application but whenever I try to translate something it comes up with this missing valid API error.

I\'ve

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 07:45

    The error on API key means you didn't create or use the key properly. You need to do the following for the key to work:
    1) create a service account [1]
    2) create a key for above service account [2]
    3) download the key to a location, for example, a local path
    4) set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the key, refer to samples in Quickstart tutorial

    Doing 1) and 2) in GCP Console, 3) and 4) in Cloud Shell would be the easiest.

    [1] https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating_a_service_account
    [2] https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys

提交回复
热议问题