5

Surely someone else is using the API, I've looked and searched, I cannot seem to find the correct value to place for the scope parameter when authenticating:

I've looked at all these scope lists, nothing, tried the OAuth 2.0 playground, translation is not there.

oauth playground v1

oauth playground v2

oath supported scopes

auth scopes

Any clues welcomed, thank you.

Error message:

Error: invalid_request

Missing required parameter: scope

Learn more
Request Details

Update

User Ezra explained that OAuth2 authentication is not needed for the Translation API.

I got down this road by this path:

I was trying to make the sample code here work:

translation api sample code

And didn't have the apiclient.discovery module

from apiclient.discovery import build

I went off looking for that which landed me here to this quick-start configurator which gave me an autogenerated translation api project here:

This starter project which is supposed to be tailored for Translation API includes a whole bunch of OAuth configuration and so I wound up asking the question because of the error mentioned here

 exception calling translation api: <HttpError 400 when requesting    https://www.googleapis.com/language/translate/v2?q=zebra&source=en&alt=json&target=fr&key=MYSECRETKEYWENTHERE returned "Bad Request">

The code I'm using to make said call which errors out in this way is:

   service = build('translate', 'v2',
        developerKey='MYSECRETKEYWENTHERE')
result = service.translations().list(
  source='en',
  target=lang,
  q='zebra'
).execute()

If I make the same call directly that the error complains about, it works ok

https://www.googleapis.com/language/translate/v2?key=MYSECRETKEYWENTHERE&q=zebra&target=fr&alt=json&source=en

Updated Again

Okay, I removed all the OAuth code from the sample project and then ran it again and then finally noticed that I had a typo in my secret key... donk

Thanks for the answers!

.

Thank you

slashdottir
  • 7,835
  • 7
  • 55
  • 71

4 Answers4

5

I think you are misunderstanding what OAuth scopes are for. You didn't list any of your code, so I'm going to explain some concepts, and hope that you can apply them to your situation.


OAuth Scopes explained:

The purpose of OAuth scopes is accessing information about authenticated users. The scopes are different for each applications, and determine what information about a user that an application is granted access to.

Concretely, an OAuth request with the scope parameter as

https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile

Would show the user a prompt similar to the following when logging in:

+ View basic information about your account
    * View your name, public profile URL, and photo
    * View your gender and birthdate
    * View your country, language, and timezone
+ View your email address
    * View the email address associated with your account

While one with only https://www.googleapis.com/auth/userinfo.email would show something like:

+ View your email address
    * View the email address associated with your account

Translate API explained:

To use the Translate API, you don't have to have users authenticated with OAuth. You simply get an API Key, and provide that key in your request to the service.

The use of the Translate API is completely orthogonal to the use of OAuth.

As documented on the Translate API site, to translate something you simply make a request to

https://www.googleapis.com/language/translate/v2?parameters

with the appropriate parameters.

The parameters needed are, as listed in the documentation, the

  • API key. Use the key query parameter to identify your application.
  • Target language. Use the target query parameter to specify the language you want to translate into.
  • Source text string. Use the q query parameter to identify the string to translate.

Concretely, a request to translate the text "hello world" into German would be:

https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world

Look at the parameters specification to get an idea of what you have to supply.

What to do:

Look at the source of the Python example using the Translate API or look up the API library for the language you want to use.

You'll see in the examples that there is no mention of OAuth scopes, because it's not needed to authenticate against the Translate API service. You only need to provide your API key, and the text to be translated in your request to the service.

There may be API calls that require scope, but Translate is not one of them.


If there is some piece of information about a user that you need, you will have to look up the API and Scope needed to access that piece of information. You will then supply this information to the Translate API as necessary.

In case of 400:

If you are getting an error response, that's good, because the call to the service is working, even if it's not doing what you want.

In the case of a 400, the Translate API's response will give you a clue about your error in its response.

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "keyInvalid",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

The response above indicates that the key is invalid. You can request a new one (or find out your old one) through the Google API Console.

Summary:

  • OAuth scopes are used for requesting information about a user. You will have to identify the scope when authenticating the user, and you will have access to all information provided by those scopes.
  • The Translate API doesn't need a scope. You provide an API Key (and some other information) in your request, and it gives back the translation as documented.
  • If there is information about a user that you wish to translate, it must be done in two steps. First, collect the information by authenticating the user in the appropriate scope, and second by providing that information to the Translate API.
  • If you're getting a 400, the response will include some information you can use to debug the problem.
Ezra
  • 7,552
  • 1
  • 24
  • 28
  • Okay, thank you for that clarification. I went down this road due to this sample code (http://code.google.com/p/google-api-python-client/source/browse/samples/translate/main.py) for the translation app which requires apiclient.discovery which doesn't seem to come by default. So, I went off to find that package which led me here: https://google-api-client-libraries.appspot.com/quickstart/c/gen?api=translate&language=python&language_variant=stable&platform=appengine&version=v2 and wound up with this problem. I will update my question – slashdottir Mar 06 '13 at 19:52
  • 1
    This looks quite outdated, Google recommends using OAuth and I'm not sure you can get regular API keys anymore. – 472084 Dec 08 '17 at 12:14
1

According to Google's documentation, you have to look at the documentation for your specific API.

Update as per this Google Group question:

"The Translate API (both v1 and v2) is an unauthenticated API, so you don't need to use OAuth with it. Instead, for v2, you should use an API key, which you can get here: http://code.google.com/apis/console"

Deep in the Code
  • 572
  • 1
  • 6
  • 20
  • 1
    Thank you, that did help. You are tied with Ezra for correct answer – slashdottir Mar 07 '13 at 02:44
  • 1
    "You don't need to use OAuth"... but what if you want to? – bumpkin Apr 19 '15 at 05:11
  • 1
    My understanding is that OAuth was not an option, since it's an unauthenticated API. The choice of words "you don't need to" were taken verbatim from the Groups post; a better choice may have been "you can't". – Deep in the Code Jun 25 '15 at 19:22
0

For error message

Error: invalid_request Missing required parameter: scope

You need to add scopes in your form

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/tasks https://www-opensocial.googleusercontent.com/api/people https://www.googleapis.com/auth/plus.login" />

Please refer spring social login with linkedin,facebook,twitter and google providers.

Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38
0

Leaving this here for anyone else who stumbles upon this question: you want the https://www.googleapis.com/auth/cloud-platform scope.

Just tested this, using the latest Google Go SDK:

 creds, _ = google.CredentialsFromJSON(context.Background(), ServiceAccountJSON, "https://www.googleapis.com/auth/cloud-platform")
    opts := option.WithCredentials(creds)
    client, err = translate.NewClient(ctx, opts)
Femi
  • 64,273
  • 8
  • 118
  • 148