Will you post your php script?

11 views
Skip to first unread message

Eureka

unread,
Sep 26, 2010, 12:12:51 PM9/26/10
to API Toolbox
Hi!

I'm trying to call google's API to translate some text. Looking for
the web I only found that you code a php script to send data with POST
method in order to avoid the GET limitation. I'm wondering to know if
you will post your php script to avoid this error or at last if you
could help me with my php code to avoid it.

Thank you very much

Vision Jinx

unread,
Sep 26, 2010, 12:45:30 PM9/26/10
to API Toolbox
Hello,

The script I am using is a custom one for my site, but here is the
basics for you

http://paste-it.net/public/e417b17/

This is for use with an AJAX Post request. You send the post request
to this script, it will use PHP Curl to get the JSON data from Google,
then return the JSON string back to your AJAX callback handler.

I did notice after I pasted it that I missed adding the userip param
(which Google now requires) so you will want to add that, but I think
the code is pretty self explanitory and you should not have any
problems going through the comments I made for it.

Cheers!
Vision Jinx

Eureka

unread,
Sep 26, 2010, 2:05:50 PM9/26/10
to API Toolbox

Oh thanks for your code. In fact it's better for me to have the answer
in the php file, I mean, I don't need to use the code in js, I can do
what I want in php so with this curl acces, Do I have the "post error"
fixed?

Vision Jinx

unread,
Sep 26, 2010, 3:19:28 PM9/26/10
to API Toolbox
Hello,

I am not clear on your question or what you really mean by post error.
This script is intended to be used dynamically like with AJAX
requests. You can check out this page as it demonstrates more what
this script was for.

http://www.visionjinx.net/miniapps/glang.htm

With that being said, it really would not be hard at all to parse the
JSON data (returned from Google) using PHP also, instead of just
returning the JSON string back to your AJAX callback handler like I
have done in the above link.

Cheers!
Vision Jinx

Eureka

unread,
Sep 26, 2010, 3:47:37 PM9/26/10
to API Toolbox
What i was trying to say is that at the moment I use js to call google
function because I didn't know how to use it with php but now this
code really helps me a lot. Now I can do all I want it with php. Ommit
my last question, it was a silly question. I have test it your php
code and now I can use long strings. With this code the error of the
Get is resolved but I was asking me what are the headers for. Also I'd
like to know if you know how to wait until google has the answer, I
mean, in js you can do:

google.language.translate(text, "en", "fr", function(result) {
document.getElementById('someelement').value = result.translation;
YOUR NEXT CODE AFTER YOU HAVE THE ANSWER
});

is it possible on php?

Eureka

unread,
Sep 26, 2010, 4:49:59 PM9/26/10
to API Toolbox
Sorry, This is not as js. PHP doesn't continues until has the answer.
It was my fault. I put the incorrect translation. All my problems have
been solved

Thank you very much for all your help. :D
Reply all
Reply to author
Forward
0 new messages