Google API を使用するのはこれが初めての試みなので、途方もなく単純なものが欠けている可能性があります。
API アクセスがオンになりました。この機能用に見つけたすべての Web ベースの設定を有効にし、Web アプリケーションの Simple API Access とクライアント ID をセットアップしました。
Google が提供する PHP ライブラリを使用しています: http://code.google.com/p/google-api-php-client/
私のコードが機能していなかったので、通常は問題が解決するので、デフォルトでサンプル コードを使用しました。以下のコードをコピーしました。
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>";
私は持っている:
- APIキーである開発者キーを確認しました
- 許可されたリファラーを確認しました
- リファラーに.DOMAIN.com/を含めるように設定します
- リファラーに IP アドレスを含めるように設定する
- OAuth2 クライアント ID、シークレットなどを含めてみました
これらのどれも機能していません。私が完全に取得しているエラーは次のとおりです。
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
私は、もっと単純なコードを書く意欲を失いつつあります。何が問題なのかアドバイスはありますか?