?
Solved

Beginning with PEAR Services_google

Posted on 2009-02-16
8
Medium Priority
?
285 Views
Last Modified: 2013-11-10
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

0
Comment
Question by:Pedro Chagas
  • 4
  • 3
8 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23654591
This suggests that $google needs to be instantiated as an object.  Something like this
$google = new OOP-THING;

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 23654686
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

0
 
LVL 14

Expert Comment

by:Ionut A. Tudor
ID: 23654823
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 23654993
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
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 23663411
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
0
 
LVL 14

Accepted Solution

by:
Ionut A. Tudor earned 1500 total points
ID: 23664046
try:
$key = "//my key that I get in google API maps";
require_once '/home/tags/php/Services/Google.php';


$google = new Services_Google($key);

$google->spellingSuggestion("the planet is round");
foreach($google as $key => $result) {
echo $key."\t".$result->title."\n";
}

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 23665286
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
0
 
LVL 14

Expert Comment

by:Ionut A. Tudor
ID: 23665406
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
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question