google-translate-api: Response code 403 (Forbidden)

I recently began receiving 403 errors when using google-translate-api. Digging in to the source a bit, this is the error that is being thrown:

{
    "message": "Response code 403 (Forbidden)",
    "host": "translate.google.com",
    "hostname": "translate.google.com",
    "method": "GET",
    "path": "/translate_a/single?client=t&sl=en&tl=fr&hl=fr&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&kc=7&q=A-Z%20Site%20Index&tk=801225.801225",
    "statusCode": 403,
    "statusMessage": "Forbidden"
}

Based on this comment, it seems that Google may have added in some rate limiting that may affect this module. Can you verify if this is the root cause?

About this issue

Commits related to this issue

Most upvoted comments

So, what’s the best practice? Will somebody fix this bug?

I forked google-translate-api and google-translate-token and made it work.

You can try by installing:

npm i vitalets/google-translate-api

UPDATE: Published to npm as @vitalets/google-translate-api:

npm i @vitalets/google-translate-api

See also https://github.com/matheuss/google-translate-api/issues/79#issuecomment-443428475

I changed the line 35 to client: 'gtx', instead of client: 't', and it’s working for me now.

I’ve published to npm working scoped package @vitalets/google-translate-api:

npm install @vitalets/google-translate-api

After install don’t forget to use scope in require:

-- const translate = require('google-translate-api');
++ const translate = require('@vitalets/google-translate-api');

Also I’ve added client parameter to be able to set client: 'gtx' instead of client: 't':

const translate = require('@vitalets/google-translate-api');

translate('Ik spreek Engels', { client: 'gtx', to: 'en' })
  .then(res => console.log(res.text)); // => "I speak English"

gtx no longer functions correctly.

After looking at it it seems to be a way for Google Translate Plugin to receive translations without creating a token. Thus it was never meant to be used for many translations. Vitalets as well as matheuss’s forks are creating incorrect tokens which is seriously affecting functionality.

Could a team be brought together to fix such errors who know how to work with this? I would be of limited help but I do want to help, this would be a huge help.

Could you publish it to npm? @vitalets

I can make a scoped package, but frankly speaking I’m not a fan of many similar packages in npm.

Hi @matheuss, could you kindly have a look on matheuss/google-translate-token#12 and merge it? As it blocks the functionality of both packages. Thanks in advance!

@vitalets your solution is no longer working for me. I forked google-translate-api as well and edited index.js line 35 as suggested, from client: 't', to client: 'gtx',. That did the trick. Hopefully the npm package will be fixed soon, but until then if you want you can just add "google-translate-api": "AlooAkbar/google-translate-api", to your package.json

Could you publish it to npm? @vitalets

I can make a scoped package, but frankly speaking I’m not a fan of many similar packages in npm.

Hi @matheuss, could you kindly have a look on https://github.com/matheuss/google-translate-token/issues/12 and merge it? As it blocks the functionality of both packages. Thanks in advance!