Re: [trnslate v2 API ] TypeError: response.data is undefined

632 views
Skip to first unread message

Jeremy Geerdes

unread,
Oct 19, 2012, 10:52:59 AM10/19/12
to google-ajax...@googlegroups.com
It's really hard to say what's going on simply by looking at the code. Can you provide a link to your page, working or not? That way we can wield some debugging tools on the thing. Alternatively, you might want to use WebKit/Chrome/Safari debugging tools or Firebug to check for error messages in the server's response. The new version of the API, in general, provides much more useful error messages than the old one did.

It might also benefit you to post to the dedicated Translate API forum, linked below:

https://groups.google.com/forum/#!forum/google-translate-api

Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

For more information or a project quote:

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

On Oct 19, 2012, at 7:41 AM, Marcin Mazanek wrote:

Hello,
I tried to check the example from the api Google Translate page on my domain (from referer restriction), I put this simple code, from google docs:

<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Translate API Example</title>
  </head>
  <body>
    <div id="sourceText">Hello world</div>
    <div id="translation"></div>
    <script>
      function translateText(response) {
        document.getElementById("
translation").innerHTML += "<br>" + response.data.translations[0].translatedText;
      }
    </script>
    <script>
      var newScript = document.createElement('script');
      newScript.type = 'text/javascript';
      var sourceText = escape(document.getElementById("sourceText").innerHTML);
      // WARNING: be aware that YOUR-API-KEY inside html is viewable by all your users.
      // Restrict your key to designated domains or use a proxy to hide your key
      // to avoid misuage by other party.
      var source = 'https://www.googleapis.com/language/translate/v2?key=*******&source=en&target=de&callback=translateText&q=' + sourceText;
      newScript.src = source;

      // When we add this script to the head, the request is sent off.
      document.getElementsByTagName('head')[0].appendChild(newScript);
    </script>
  </body>
  </html>


But I received na error in firebug:

TypeError: response.data is undefined
...lementById("translation").innerHTML += "<br>" + response.data.translations[0].tr...

I don't really know. What is wrong ?

Could you help me?

I will appreciate it.

Marcin

--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to
google-ajax-searc...@googlegroups.com
To view this message on the web, visit
https://groups.google.com/d/msg/google-ajax-search-api/-/SvXl3Q8hbEEJ
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en

Marcin Mazanek

unread,
Oct 19, 2012, 11:31:49 AM10/19/12
to google-ajax...@googlegroups.com
What I pasted is everything I have in this code. I only tested it to check if it works. The code is the same as in google example from the webiste:
https://developers.google.com/translate/v2/getting_started?hl=pl
I only add my app Id to it. It's strange for me that , this example doesn''t work...

ProgoldSpA

unread,
Dec 16, 2013, 9:48:48 AM12/16/13
to google-ajax...@googlegroups.com
I paste the complete error:
 

1.  Uncaught TypeError: Cannot read property 'translations' of undefined attivita.asp?clien=7460C&reset=1:428

1.  translateText1attivita.asp?clien=7460C&reset=1:428

2.  (anonymous function)

https://www.googleapis.com/language/translate/v2?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&source=en&target=it&callback=translateText1&q=this%20is%20a%20translation%20test%20to%20check%20its%20functionality.

 

// API callback

translateText1({

"error": {

  "errors": [

   {

    "domain": "usageLimits",

    "reason": "accessNotConfigured",

    "message": "Access Not Configured"

   }

  ],

  "code": 403,

  "message": "Access Not Configured"

}

}

);

Jeremy Geerdes

unread,
Dec 16, 2013, 11:39:16 AM12/16/13
to google-ajax...@googlegroups.com
Here are some things to check: Have you set up access in the APIs Console? If yes, are you including the API key properly in your request? If yes, then have you set up IP or referer restrictions which are blocking your app (test this by removing any such restrictions)? If you're still having problems after working through all of these, you'll probably want to post to the Translate API forum, which is here:


Be advised, though, they're sometimes a bit slow to respond.

jg





--
--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to

To view this message on the web, visit
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-searc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!
Reply all
Reply to author
Forward
0 new messages