2016-10-05 7 views
0

Google翻訳APIを使用しているときに、現在400のエラーが発生しています。「お客様のクライアントは不正または不正なリクエストを出しました。Google Translate APIを使用した場合のエラー400

ブラウザにURLを直接使用すると問題なくOKです。 cf.ここでhttps://www.googleapis.com/language/translate/v2?key=[KEY]&target=fr&q=Centrally%20located,%20huge%20room,%20super%20design%20of%20the%20bathroom,%20bathtube&source=en

は私のPHPコードです:

$base_url = 'https://www.googleapis.com/language/translate/v2?'; 
$url = $base_url.'key='.$this->api_key.'&target='.$target.'&q='.$text; 
if ($source) { 
    $url .= '&source='.$source; 
} 
$c = curl_init(); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($c, CURLOPT_URL, $url); 
curl_setopt($c, CURLOPT_HEADER, 0); 
$contents = curl_exec($c); 

任意のアイデア?ありがとう。

答えて

0

OK、解決策を見つけました。

私は追加する必要があります。

$text = strip_tags($text); 
$text = str_replace(' ', '+', $text); 
関連する問題