2010-12-04 5 views
0

Comment puis-je utiliser la méthode POST pour Google Translate. Je ne veux pas utiliser JS pour une raison quelconque, besoin de le faire avec PHP. Ce qui suit ne fonctionne pas.Comment puis-je utiliser la méthode POST pour Google Translate

public static function googleTranslatePost($text = "What are you looking at", $destLang='fr', $srcLang = 'en') 
    { 

    $http_response = ''; 
    $ch = curl_init('http://translate.google.com/translate_t'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,'hl=en&ie=UTF8&text=-->this+is+a+test<--&langpair=en%7Car'); 
    curl_setopt($ch, CURLOPT_POST,true); 
    curl_setopt($ch, CURLOPT_HEADER,false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
    $http_response = curl_exec($ch); 
    return $http_response; 

    } 
+0

Que se passe ou ne se passe pas? –

+0

Je ne reçois aucune réponse ni erreur de la part de php. – YumYumYum

+0

TRAVAIL MAINTENANT - https://gist.github.com/728228 – YumYumYum

Répondre

1

Salut, j'ai trouvé ce cours sur google. Permettez-moi de savoir si cela est utile:

http://code.google.com/p/gtranslate-api-php/

+0

NE FONCTIONNE PAS. avec ce noyau soit eX: https://gist.github.com/728196 – YumYumYum

+0

non cela a fonctionné à partir d'ici! – tawfekov

+0

En méthode GET: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en|fr Donne -> {"responseData": {"translatedText": "bonjour" }, "responseDetails": null, "responseStatus": 200} -> Mais le mien POST ne fait rien – YumYumYum

Questions connexes