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

前端 未结 3 1678
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  猫巷女王i
    2020-12-21 07:36

    If you are using client library and you have already downloaded your service account json file try below

     // Instantiates a client
     const translate = new Translate(
            {
                    projectId: 'your project id', //eg my-project-0o0o0o0o'
                    keyFilename: 'path of your service acount json file' //eg my-project-0fwewexyz.json
            }
        ); 
    

    instead of

      // Instantiates a client
      const translate = new Translate({projectId});
    

    this way you need only your the service acount json file and the specific API enabled

提交回复
热议问题