Results 1 to 3 of 3
  1. #1
    coolFrenzi is offline Member
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

    Default [SOLVED] Using yahoo search api

    Hello,
    I am trying to use yahoo search api with java. I got this code from their website but it does not run and gives errors like package does not exist. Can some one help me out? Do I need to download a package?

    Java Code:
    import java.io.*;
    
    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.*;
    
    public class YahooWebServiceGet {	
    	
    	public static void main(String[] args) throws Exception {
    		String request = "http ://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=umbrella&results=10";
                
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(request);
            
            // Send GET request
            int statusCode = client.executeMethod(method);
            
            if (statusCode != HttpStatus.SC_OK) {
            	System.err.println("Method failed: " + method.getStatusLine());
            }
            InputStream rstream = null;
            
            // Get the response body
            rstream = method.getResponseBodyAsStream();
            
            // Process the response from Yahoo! Web Services
            BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            br.close();
    	}
    
    }

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    804
    Rep Power
    6

    Default

    Hi,
    Are you having "commons-httpclient.jar" in classpath?
    -Regards
    Ramya

  3. #3
    coolFrenzi is offline Member
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 06-17-2009, 11:24 AM
  2. Replies: 6
    Last Post: 04-10-2009, 02:08 AM
  3. Replies: 5
    Last Post: 08-26-2008, 03:43 PM
  4. Replies: 3
    Last Post: 07-16-2007, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •