Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9068915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:18:10+00:00 2026-06-16T17:18:10+00:00

I have the ZF first old function working before but somehow ZF it was

  • 0

I have the ZF first old function working before but somehow ZF it was failing, and then i made the unittest module.

I am trying to use the google translation v2 but it never works anymore, did Google stop there service for public use or is it PHP Bug or somewhere else confusing very much.

Always returning 403 with both following functions.

Any idea whats going wrong?

<?php
## Test: How to's
/*
$ php tst.php 
403

$ curl http://ajax.googleapis.com/ajax/services/language/translate -d "v=1.0&q=dog&langpair=en|ru" -H "Referer: http://google.com"
{"responseData": null, "responseDetails": "Please use Translate v2.  See http://code.google.com/apis/language/translate/overview.html", "responseStatus": 403}sun@sun-M14xR2:/var/www/html/vooyz.com/unittest$ 

*/

// V1 - Old not working
function googleTranslatePostV1($text, $destLang = 'nl', $srcLang = 'en') {
  $url = 'http://ajax.googleapis.com/ajax/services/language/translate';
  $http_response = '';
  $text = urlencode($text);
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_REFERER, !empty($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "");
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "v=1.0&q=" . $text . "&langpair=$srcLang|$destLang");
  $http_response = curl_exec($ch);
  $json = json_decode($http_response, true);

  if ($json['responseStatus'] != '200') {
    return $json['responseStatus'];
  } else {
    return $json['responseData']['translatedText'];
  }
  curl_close($ch);
}

// V2 - Curl way not working
function googleTranslatePostV2($text, $destLang = 'nl', $srcLang = 'en') {
  $url = 'https://www.googleapis.com/language/translate/v2';
  $http_response = '';
  $text = urlencode($text);
  $postArr = array('key' => 'sdfdsfdsfds',
          'q' => $text,
          'source' => $srcLang,
          'target' => $destLang);

  $ch = curl_init();    
  //curl_setopt($ch, CURLOPT_POSTFIELDS,'hl=en&ie=UTF8&text=-->this+is+a+test<--&langpair=en%7Car');      
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);       
  curl_setopt($ch, CURLOPT_REFERER, !empty($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "");
  curl_setopt($ch, CURLOPT_POST,true);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$postArr);        
  $http_response = curl_exec($ch);

  var_dump($http_response);

  $json = json_decode($http_response, true);

  if ($json['responseStatus'] != '200') {
    return $json['responseStatus'];
  } else {
    return $json['responseData']['translatedText'];
  }
  curl_close($ch);
}


// V2 - Google way
function googleTranslateV2Method1($text, $destLang = 'nl', $srcLang = 'en') {
  require_once 'google/src/Google_Client.php';
  require_once 'google/src/contrib/Google_TranslateService.php';
  $client = new Google_Client();
  $client->setApplicationName('Google Translate PHP Starter Application');
  $client->setDeveloperKey('dsfdsfdsf');
  $service = new Google_TranslateService($client);

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

  return $translations;
}

echo googleTranslatePostV1("V1: " . "How are you?") . "\n";
echo googleTranslatePostV2("V2: " . "How are you?") . "\n";
echo googleTranslateV2Method1("V2: " . "How are you?") . "\n";


?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:18:10+00:00Added an answer on June 16, 2026 at 5:18 pm
    $ curl http://ajax.googleapis.com/ajax/services/language/translate -d "v=1.0&q=dog&langpair=en|ru" -H "Referer: http://google.com"
    
    {"responseData": null, "responseDetails": "Please use Translate v2.  See http://code.google.com/apis/language/translate/overview.html", "responseStatus": 403}
    

    http://code.google.com/apis/language/translate/overview.html :
    Google
    Translate API is available as a paid service. See the Pricing and FAQ
    pages for details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with xslt for the first time. I have 2.0, but that's about
Bascially you have first to do a: SurfFeatureDetector surf(400); surf.detect(image1, keypoints1); And then a:
In order to add events we could use this simple first solution : function
I have been working on a project and trying to find the source of
I have build an app that use mp3-files. In the first version the files
i have a simple function i used to use to do login remotely to
I have trouble with the printing function of the WebBrowser control. First i load
Ok, I have this script working 99% of how it should be working, but
I have two elements and will get strings inside. (and i use .each` function)
I'm trying to migrate a lot of old PHP mysql prodecural function like mysql_query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.