Newbie - Google API

Discussion in 'Java' started by Jacky, Apr 30, 2005.

  1. Jacky

    Jacky Guest

    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
     
    Jacky, Apr 30, 2005
    #1
    1. Advertising

  2. Jacky

    Rhino Guest

    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" <> wrote in message
    news:...
    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
     
    Rhino, Apr 30, 2005
    #2
    1. Advertising

  3. Jacky

    Jacky Guest

    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);
    }
    }
    ================================================
     
    Jacky, May 1, 2005
    #3
  4. Jacky

    Betty Guest

    "Rhino" <> wrote in message
    news:jITce.16924$...
    > 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.
     
    Betty, May 1, 2005
    #4
  5. Jacky

    Jacky Guest

    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.
     
    Jacky, May 1, 2005
    #5
  6. 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:
     
    Peter MacMillan, May 1, 2005
    #6
  7. Jacky

    Jacky Guest

    thanks!! I was adding the path, til u mentioned about adding a jar!!

    I modified it to a jar, and it works!! thanks!!
     
    Jacky, May 2, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Thompson

    FAQ - references to Google/Google Groups

    Andrew Thompson, Jun 20, 2005, in forum: Java
    Replies:
    0
    Views:
    629
    Andrew Thompson
    Jun 20, 2005
  2. Replies:
    2
    Views:
    2,036
    Jeffrey Schwab
    Nov 28, 2005
  3. Krice
    Replies:
    9
    Views:
    295
    Default User
    Apr 25, 2008
  4. Ethan Herdrick
    Replies:
    1
    Views:
    109
    Ethan Herdrick
    May 11, 2006
  5. Replies:
    0
    Views:
    493
Loading...

Share This Page