Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

Beginning with PEAR Services_google

Hi, First I have to tell, in API services I don't have any knowledge.
I work well with other scripts of PEAR, like language detect and some others, but Services Google is more difficulty because is involve other identity or other site, in this case google.
I have now a API key, I get from maps (I think with one key I can get to the others API's).
I Have interest in special by 'spelling suggestions' of Service_Google!
Like I tell above, I don't have any experience in google API's, I copy the code you can see in code snippet and I do some little changes, like put my key inside $key.

So, if I want to use 'spelling suggestions' the code in code snippet is the correct? I don't think so, and I don't have any idea what that script do! And when I try in my server I get this #error:
Fatal error: Call to a member function search() on a non-object in /home/tags/public_html/bastidores/teste.php on line 47.

Who give me a help to working with spelling suggestions or Services_Google (PEAR)?

Regards,
JC
 
$key = "//my key that I get in google API maps";
require_once '/home/tags/php/Services/Google.php';
$google->search("PEAR"); //line 47 line 47 line 47
foreach($google as $key => $result) {
echo $key."\t".$result->title."\n";
}

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This suggests that $google needs to be instantiated as an object.  Something like this
$google = new OOP-THING;

Open in new window

Avatar of Pedro Chagas

ASKER

I tell my knowledge in API is not to much, so I don't understand the new line 1:  $google = new OOP-THING;
What I write to replace the word OOP-THING?
I do that changes in the code, I replace $google->search("PEAR"); for  $google = new OOP-THING; and I get this error: Fatal error: Class 'OOP' not found in /home/tags/public_html/bastidores/teste.php on line 47

Can you be more precise.

Regards,
JC
$key = "MY KEY";
require_once '/home/tags/php/Services/Google.php';
 $google = new OOP-THING; //line 47 line 47 line 47
foreach($google as $key => $result) {
echo $key."\t".$result->title."\n";
}

Open in new window

Avatar of Ionut A. Tudor
You need to initiate the class like Ray_Paseur suggested.

This is the way: $google = new Services_Google($key);

or if this doesn't work open file Google.php in notepad or your editor and search for class name and replace it with above `Services_Google`. The final code should look like below code. Also to learn more about OOP go here: http://serialize.us/?page_id=92


$key = "//my key that I get in google API maps";
require_once '/home/tags/php/Services/Google.php';
$google = new Services_Google($key);
$google->search("PEAR"); //line 47 line 47 line 47
foreach($google as $key => $result) {
echo $key."\t".$result->title."\n";
}

Open in new window

With the new code, I don't get any error, but I don't get anything, appear a blank page.
I go to http://serialize.us/?page_id=92, like you tell me, I read, but the examples is just to get names of books, and I want work with 'spelling suggestions'.

After I have this code, what I have to do?
$key = "//my key that I get in google API maps";
require_once '/home/tags/php/Services/Google.php';
$google = new Services_Google($key);
$google->search("PEAR"); //line 47 line 47 line 47
foreach($google as $key => $result) {
echo $key."\t".$result->title."\n";
}

Give me just a little example, after I get a little example maybe I understand more difficulty things.

Regards,
JC
I check the file Google.php of PEAR in my server, and I found the function that made what I want about 'spelling suggestions'. I copy the function:
===============================
/**
     * Does a spell check using Google's spell checking engine.
     *
     * @param   string $phrase The string to spell check.
     * @return  string A suggestion of how the phrase should be spelt.
     * @access  public
     */
    public function spellingSuggestion($phrase)
    {
        return $this->_soapClient->doSpellingSuggestion($this->key, $phrase);
    }
=======================================

If I have a phrase or string like $string = "the planet is round"; how I use the string in function above?

Don't forget, I have this code:
$key = "//my key that I get in google API maps";
require_once '/home/tags/php/Services/Google.php';
$google = new Services_Google($key);
$google->search("PEAR"); //line 47 line 47 line 47
foreach($google as $key => $result) {
echo $key."\t".$result->title."\n";
}

Please tell me how I use the function spellingSuggestion?

Regards, JC
ASKER CERTIFIED SOLUTION
Avatar of Ionut A. Tudor
Ionut A. Tudor
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
About the code of 'al3cs12', I thing is work. But now I have a problem of invalid key, and the system when I ruyn the script give me this message:
=======================================
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Invalid key: ABQIAAAAqfY-BfCgaVIYFbuvkKMFNBQUy4sC81vI6rN4yOTiPQw_uMNI8hTIerz3C-GAZJMFL61uR51YZNBCCw in /home/tags/php/Services/Google.php:211 Stack trace: #0 [internal function]: SoapClient->__call('doSpellingSugge...', Array) #1 /home/tags/php/Services/Google.php(211): SoapClient->doSpellingSuggestion('ABQIAAAAqfY-BfC...', 'the planet is r...') #2 /home/tags/public_html/bastidores/teste.php(18): Services_Google->spellingSuggestion('the planet is r...') #3 {main} thrown in /home/tags/php/Services/Google.php on line 211
=======================================

I get that key from map API, but like you see, that key don't work in spelling suggestion.
Where is the righ place or API to get a key for my script?

Thanks to 'al3cs12' by code!

Regards, JC
the php code is working but you should get a valid key from google API, i'm not familiar with this but you should check out http://code.google.com/intl/en/, and if any new problems arrise you can open a new questions. Good luck