Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Newbie - Google API

Reply
Thread Tools

Newbie - Google API

 
 
Jacky
Guest
Posts: n/a
 
      04-30-2005
Hi,

I have some problems using google API in java. I am using JCreator, and
got the following messages:


GoogleAPIDemo.java:35: cannot resolve symbol
symbol : class GoogleSearch
location: class com.google.soap.search.GoogleA*PIDemo
GoogleSearch s = new GoogleSearch();
^
GoogleAPIDemo.java:35: cannot resolve symbol
symbol : class GoogleSearch
location: class com.google.soap.search.GoogleA*PIDemo
GoogleSearch s = new GoogleSearch();
^
GoogleAPIDemo.java:42: cannot resolve symbol
symbol : class GoogleSearchResult
location: class com.google.soap.search.GoogleA*PIDemo
GoogleSearchResult r = s.doSearch();
^
GoogleAPIDemo.java:61: cannot resolve symbol
symbol : class GoogleSearchFault
location: class com.google.soap.search.GoogleA*PIDemo
} catch (GoogleSearchFault f) {
^
4 errors



I have added the path to googleapi.jar in my JCreator, but still have
the above problems.



Thanks,
Jacky

 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      04-30-2005
Is it possible that you forgot the import statements that you need to pick
up the Google classes? If you're sure the imports are present in your source
code, check these things:
- Does the Google jar contain the classes you think it does? Use the jar
command to display the contents of the jar to be sure. Perhaps you
downloaded the wrong jar....
- Is the Google jar really where you think it is? Perhaps you put it one
directory higher or lower than you thought when you added the path to the
classpath.
- Is the path you specified to the Google jar the same as the path that
specifies where the Google jar actually is?

By the way, where did you find this Google API? I've never heard of a Google
API for Java and might be interested in using it myself on a future project.

Rhino


"Jacky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
Hi,

I have some problems using google API in java. I am using JCreator, and
got the following messages:


GoogleAPIDemo.java:35: cannot resolve symbol
symbol : class GoogleSearch
location: class com.google.soap.search.GoogleA*PIDemo
GoogleSearch s = new GoogleSearch();
^
GoogleAPIDemo.java:35: cannot resolve symbol
symbol : class GoogleSearch
location: class com.google.soap.search.GoogleA*PIDemo
GoogleSearch s = new GoogleSearch();
^
GoogleAPIDemo.java:42: cannot resolve symbol
symbol : class GoogleSearchResult
location: class com.google.soap.search.GoogleA*PIDemo
GoogleSearchResult r = s.doSearch();
^
GoogleAPIDemo.java:61: cannot resolve symbol
symbol : class GoogleSearchFault
location: class com.google.soap.search.GoogleA*PIDemo
} catch (GoogleSearchFault f) {
^
4 errors



I have added the path to googleapi.jar in my JCreator, but still have
the above problems.



Thanks,
Jacky


 
Reply With Quote
 
 
 
 
Jacky
Guest
Posts: n/a
 
      05-01-2005
Hi Rhino,

Google API is available here:
http://www.google.com/apis/



And the sample source code is here:
================================================
/* Copyright (C) 2002, Google, Inc. */
package com.google.soap.search;
import java.io.*;

/**
* The GoogleAPIDemo is a demonstration of using the Google Web APIs
for
* search and fetching pages from the cache.
*
* @see com.google.soap.search.GoogleSearch
* @see com.google.soap.search.GoogleSearchResult
*/


public class GoogleAPIDemo {
/** Demonstration program to call the Google Web APIs service.
** Usage:<br>
** <tt>java com.google.soap.search.GoogleAPIDemo [key] search
Foo</tt><br>
** <tt>java com.google.soap.search.GoogleAPIDemo [key] cached
http://www.google.com/</tt>
** <tt>java com.google.soap.search.GoogleAPIDemo [key] spell
"britnay spars"</tt>
**/
public static void main(String[] args) {
// Parse the command line
if (args.length != 3) {
printUsageAndExit();
}
String clientKey = "R+9Hco9QFHIHTO1cqDeWV+msvvP1DZTk";
String directive = "search";
String directiveArg = args[2];

// Report the arguments received
System.out.println("Parameters:");
System.out.println("Client key = " + clientKey);
System.out.println("Directive = " + directive);
System.out.println("Args = " + directiveArg);

// Create a Google Search object, set our authorization key
GoogleSearch s = new GoogleSearch();
s.setKey(clientKey);

// Depending on user input, do search or cache query, then print
out result
try {
if (directive.equalsIgnoreCase("search")) {
s.setQueryString(directiveArg);
GoogleSearchResult r = s.doSearch();
System.out.println("Google Search Results:");
System.out.println("======================");
System.out.println(r.toString());
} else if (directive.equalsIgnoreCase("cached")) {
System.out.println("Cached page:");
System.out.println("============");
byte [] cachedBytes = s.doGetCachedPage(directiveArg);
// Note - this conversion to String should be done with
reference
// to the encoding of the cached page, but we don't do that
here.
String cachedString = new String(cachedBytes);
System.out.println(cachedString);
} else if (directive.equalsIgnoreCase("spell")) {
System.out.println("Spelling suggestion:");
String suggestion = s.doSpellingSuggestion(directiveArg);
System.out.println(suggestion);
} else {
printUsageAndExit();
}
} catch (GoogleSearchFault f) {
System.out.println("The call to the Google Web APIs failed:");
System.out.println(f.toString());
}
}

private static void printUsageAndExit() {
System.err.println("Usage: java " +
GoogleAPIDemo.class.getName() +
" <client-key>" +
" (search <query> | cached <url> | spell
<phrase>)");
System.exit(1);
}
}
================================================

 
Reply With Quote
 
Betty
Guest
Posts: n/a
 
      05-01-2005

"Rhino" <(E-Mail Removed)> wrote in message
news:jITce.16924$(E-Mail Removed) ...
> Is it possible that you forgot the import statements that you need to pick
> up the Google classes? If you're sure the imports are present in your

source
> code, check these things:
> - Does the Google jar contain the classes you think it does? Use the jar
> command to display the contents of the jar to be sure. Perhaps you
> downloaded the wrong jar....
> - Is the Google jar really where you think it is? Perhaps you put it one
> directory higher or lower than you thought when you added the path to the
> classpath.
> - Is the path you specified to the Google jar the same as the path that
> specifies where the Google jar actually is?
>
> By the way, where did you find this Google API? I've never heard of a

Google
> API for Java and might be interested in using it myself on a future

project.

I got this several months ago and followed the instructions, and it worked
fine.
I don't remember where I got it so I just now did a google for it and it is
at
http://www.google.com/apis/
First you get their stuff, then you register with them and get a key from
them,
then you can use their stuff to try it out. There is all the code you need
to
get started and actually do queries and get results. Maybe the OP just made
a
simple error. They limit you to something like 1,000 (or maybe it is 10,000)
queries/day, but if you need more you can work with them (this means you
give them money) to do more. There is also a limit of something like 10
results
returned to you per query, but they tell you how to automatically combine
queries to get more at a time. It's fun.


 
Reply With Quote
 
Jacky
Guest
Posts: n/a
 
      05-01-2005
I can run the program if I type the following in the command line,
java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo <key>
search <keywords>

But I can't compile the sample source codes.

 
Reply With Quote
 
Peter MacMillan
Guest
Posts: n/a
 
      05-01-2005
Jacky wrote:
> Hi,
>
> I have some problems using google API in java. I am using JCreator, and
> got the following messages:

[snip]
>
> I have added the path to googleapi.jar in my JCreator, but still have
> the above problems.
>


You need to specify the *jar* file, not just the path to it (or *.jar in
a dir with the jar file, or put it in the classpath). The errors you
posted *specifically* mean that the jar hasn't been used.


javac -cp googleapi.jar GoogleAPIDemo.java


java -cp GoogleAPI.jar com.google.soap.search.GoogleAPIDemo mykey search
java


Parameters:
Client key = mykey
Directive = search
Args = java
[and then a whole lot of result data]



Adding a jar in your IDE is OT here - find a forum dedicated to your ide
as it is an ide issue and not a java issue (and you'll have an easier
time finding people who know how the specific IDE works).

--
Peter MacMillan
e-mail/msn: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Jacky
Guest
Posts: n/a
 
      05-02-2005
thanks!! I was adding the path, til u mentioned about adding a jar!!

I modified it to a jar, and it works!! thanks!!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for Google API expert to consult on our Google hosted apps(calendar, maps, email, docs) styles@xlsuite.com Ruby 0 11-20-2007 04:21 AM
Profiling API or Membership API John123 ASP .Net 0 10-20-2006 03:18 PM
Ruby/Google (Ruby abstraction of Google API) is dead? Ethan Herdrick Ruby 1 05-11-2006 06:38 AM
Calling the C API from Python and Python program from same C API -bidirectional Praveen, Tayal (IE10) Python 0 03-17-2005 06:33 AM
What API replaces the unlock API that existed in gcc 2.9.3? Shlomo Anglister C++ 1 08-02-2004 06:50 PM



Advertisments