Fatemah Alnofal
Fatemah Alnofal

Reputation: 11

'Request had insufficient authentication scopes' from Google Translate API in R

I am currently working on analyzing twitter data , however when I attempt to translate twitter text data through the translate() package leveraging the use of Google API in R I get this error.

 t <- gl_translate(my_data$text, source="ar", target="en", )
2020-07-19 11:25:30 -- Translating text: 69597 characters - 
ℹ 

2020-07-19 11:25:32 > Request Status Code:  400

2020-07-19 11:25:32 -- API returned: Request payload size exceeds the limit: 204800 bytes.
2020-07-19 11:25:32 -- Attempting to split into several API calls
2020-07-19 11:25:32 -- Translating text: 98 characters - 
Auto-refreshing stale OAuth token.
ℹ 2020-07-19 11:25:33 > Request Status Code:  403
Error: API returned: Request had insufficient authentication scopes.

why does it produce this error?

this is my code:

gar_auth(email="**@**.com")
set.key('****')
t <- gl_translate(my_data$text, source="ar", target="en", )
View(t)

Upvotes: 1

Views: 628

Answers (1)

user13653858
user13653858

Reputation:

If you use googleLanguageR package (it is not clear from the question itself), it seems like an authentication issue.

You'll probably need to authenticate with:

library(googleLanguageR)
gl_auth("translate_api_key.json")

To get the JSON authentication file, see Google Cloud Translation - Creating service accounts and keys.

For details on authenticating the googleLanguageR package in R, see Language tools for R via Google Machine Learning APIs - Authentication.

Note that Google API has some pricing for this.

If you want to use a Google Translate API key rather than JSON file, there are:

  • translate package, where you store you API key in getOption("google.key") variable, or you pass a key argument with you API key, and
  • github/sumtxt/datatools package with gl_translate() function, where you can provide the API key in the key argument as well,

but note that you have to generate you API key in Google Cloud Console as well (not to be confused with a password of your Google account).

Upvotes: 1

Related Questions