{---------------------最終更新-----------------}本番環境用のAPIがまもなく必要になりますいつか、でも今は慣れたかっただけです。そして、私は時間を節約するためにそれを一度だけ使用していました。(しかし、私は丸2日を使用することになりました...)とにかく私はこれのためにgtranslateを見つけました。それで、私はそれがさらに進んでいる将来のいつか実際のAPIを見るでしょう。:D
回避策を見つけました。
{ - - - - - - - - - - - - - - - - アップデート - - - - - - - - ---------------------------}
私の最初の投稿以来、私はprodigitalsonとDavid Gillenの助けを借りて少し遠くまで行くことができましたが、私はまだ途方に暮れています。
不思議なSLLエラーが発生していたので、オンラインで少し読んだところ、証明書を作成するように言われました。とにかく、その結果、私は朝のほとんどをプログラミング地獄で過ごしました。それは、動作しなかったWindowsでソースopensllからコンパイルしようとしたためです。そして、私はそのアイデアをあきらめて、curl_setopt($ ch、CURLOPT_SSL_VERIFYPEER、0)の使用を提案する投稿を見つけました。行とそれは問題を処理しました、今私が得ているエラーは次のとおりです:
Fatal error: Uncaught exception 'apiAuthException' with message
'Couldn't fetch request token, http code: 400, response body: Invalid scope:
https://www.googleapis.com/auth/translate ' in
C:\xampp\htdocs\translate\google-api-php-client2\src\auth\apiOAuth.php:191
Stack trace:
#0
C:\xampp\htdocs\translate\google-api-php-client2\src\auth\apiOAuth.php(169):
apiOAuth->requestRequestToken('http://localhos...')
#1 C:\xampp\htdocs\translate\google-api-php-client2\src\auth\apiOAuth.php(87):
apiOAuth->obtainRequestToken('http://localhos...', '4d9609c2bc4ce')
#2 C:\xampp\htdocs\translate\google-api-php-client2\src\apiClient.php(131):
apiOAuth->authenticate(Object(apiFileCache), Object(apiCurlIO), Array)
#3 C:\xampp\htdocs\translate\lang.php(20): apiClient->authenticate()
#4 {main} thrown in C:\xampp\htdocs\translate\google-api-php-client2\src\auth\apiOAuth.php on line 191
私は今、エラーメッセージに影響を与えないようにコメントされた行が含まれているこのコードを使用しています
<?php
//session_start();
//$_session['auth_token'] = 'AIzaSyAdPfnEsdsQQ6AxSn6K78LznZXHfHZIB3M';
require_once('/google-api-php-client2/src/apiClient.php');
require_once('/google-api-php-client2/src/contrib/apiTranslateService.php');
$apiClient = new apiClient();
$translate = new apiTranslateService($apiClient);
//If a oauth token was stored in the session, use that- and otherwise go through the oauth dance
if (isset($_SESSION['auth_token'])) {
$apiClient->setAccessToken($_SESSION['auth_token']);
}
else {
//In a real application this would be stored in a database, not in the session
$_SESSION['auth_token'] = $apiClient->authenticate();
}
//$translate->listTranslations('Hello to the world of space', 'fr', 'text', 'en');
{----------------------------------以下の元の投稿------------ --------------------}
あらゆる種類のAPIを使用するのはこれが初めてであり、何よりも苛立たしいものです。
GoogleTranslateAPIをPHPで動作させようとしています。残念ながら、ドキュメントはダミーの証拠ではないので、私は迷子になっています。
私はこのドキュメントを上下左右に読みました:http ://code.google.com/apis/language/translate/v2/getting_started.html
ここに表示されているPHPAPIクライアントをダウンロードしましたhttp://code.google.com/apis/language/translate/v2/libraries.html
そして私は特にこのスクリプトを使おうとしています: http ://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/apiTranslateService.php
OOP *の実装方法がよくわからないので、これが私の落とし穴です。ドキュメントには、APIキーを使用する必要があると記載されていますが、PHPAPIクライアントのどこに配置する必要があるかがわかりません。
これまでのところ、これは私が試みたものです:
<?php
include('../google-api-php-client/src/apiClient.php');
include('../google-api-php-client/src/contrib/apiTranslateService.php');
$a = new apiTranslateService;
$a->listTranslateions('Hello to the world of space', 'fr', 'text', 'en');
?>
そしてこれが私の結果です
Catchable fatal error:
Argument 1 passed to apiTranslateService::__construct()
must be an instance of apiClient, none given, called in
C:\xampp\htdocs\translate\lang.php on line 7 and defined in
C:\xampp\htdocs\google-api-php-client\src\contrib\apiTranslateService.php on line 38
*おっと私に教えるための良いウェブサイトのリンクを知っているなら、私にそれを残してください。
皆さん、ありがとうございました