TH1981
TH1981

Reputation: 3193

Google Translate API Access Error: (403) Access Not Configured

This is my first attempt to use the Google API, so I'm probably missing something ridiculously simple.

My API access has been turned on, I've enabled all the web based settings I could find for this feature, setup the Simple API Access and Client ID for web applications, etc.

I'm using the PHP library Google provide here: http://code.google.com/p/google-api-php-client/

As my code wasn't working, I defaulted to their sample code as getting that working usually solves my problems. I've copied their code below:

require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_TranslateService.php';

$client = new Google_Client();
$client->setApplicationName('Translation tool');

// Visit https://code.google.com/apis/console?api=translate to generate your
// client id, client secret, and to register your redirect uri.
$client->setDeveloperKey('XXXXXXXXXXXXXXXX');
$service = new Google_TranslateService($client);

$langs = $service->languages->listLanguages();
print "<h1>Languages</h1><pre>" . print_r($langs, true) . "</pre>";

$translations = $service->translations->listTranslations('Hello', 'hi');
print "<h1>Translations</h1><pre>" . print_r($translations, true) . "</pre>";

I have:

None of these have worked. The error I'm getting in full is as follows:

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/language/translate/v2/languages?key=XXXXXXXXXXXXXXXX: (403) Access Not Configured' in /home/google-api-php-client/src/io/Google_REST.php:66 Stack trace: #0 /home/google-api-php-client/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /home/google-api-php-client/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 /home/google-api-php-client/src/contrib/Google_TranslateService.php(39): Google_ServiceResource->__call('list', Array) #3 /home/google-api-php-client/examples/translate/simple.php(13): Google_LanguagesServiceResource->listLanguages() #4 {main} thrown in /home/google-api-php-client/src/io/Google_REST.php on line 66

I'm loosing the will to code with something that should be much more straight forward. Any advice to what might be the problem?

Upvotes: 0

Views: 3174

Answers (2)

Sajjad Ashraf
Sajjad Ashraf

Reputation: 3844

i had the same problem but with the analytics api. In my case i listed the ip of the server in the allowed ip addresses.
So when i removed all ip addresses from the google api's console allowed ip addresses then it started working.

Upvotes: 0

AmmoX
AmmoX

Reputation: 26

That 403 error is almost certainly related to the Simple API Key. If for example it was a usage restriction the message would say that so....

Double check and make sure you are using the Simple API key listed for server access and have it set to any IP. Specific IP should work but it may depend on how your server is set up.

You may even want to generate a new key just to make sure the one you have is valid. Specific IP would be best in the long run.

Just did the same thing working with the Custom Search API, had the browser key entered and it caused a big dent in the wall as I banged my head into it. . You Shouldn't need any of the OAuth settings just to get the basics working.

Upvotes: 1

Related Questions