LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2012, 05:28 PM   #1
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Rep: Reputation: 15
Google APIs?


Hi, I am trying to learn how to consume a google rest api. What is a free google rest api I can consume? Thanks.
 
Old 06-24-2012, 08:07 PM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
You may find useful information here:
https://developers.google.com/translate/v2/using_rest
https://developers.google.com/custom.../v1/using_rest

Daniel B. Martin
 
Old 06-24-2012, 10:48 PM   #3
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Original Poster
Rep: Reputation: 15
Thanks, I am trying to consume the google custom search REST API with the following java code. I get an exception that says "bad request". What am I doing wrong? Here is the google api documentation I have been following: https://developers.google.com/custom...etting_started

Thanks in advance.

package googlerest;
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.*;

public class GoogleREST {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
try {
String result = httpGet("https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=SEARCHENGINE_UNIQUEID");
System.out.println(result);
}
catch(Exception e) {
System.out.println(e.getMessage());
}

}

public static String httpGet(String urlStr) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

if(conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
return sb.toString();
}
}
 
Old 06-25-2012, 06:27 AM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by ShaqDiesel View Post
Thanks, I am trying to consume the google custom search REST API with the following java code.
A gentle suggestion: if you are using a specific language (java in this case) you should say so in your first post. That will attract interest from LQers who know that language. I tried to help by pointing you to references. I know zero about java so cannot be of further service.

Daniel B. Martin
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Oracle v. Google - Judge Alsup Rules APIs Not Protected By Copyright LXer Syndicated Linux News 0 06-01-2012 04:20 AM
LXer: Oracle v Google could clear way for copyright on languages, APIs LXer Syndicated Linux News 0 04-17-2012 10:40 AM
LXer: Google to enforce SSL encryption on developer APIs LXer Syndicated Linux News 0 03-19-2011 03:50 PM
"Quick Links" and Google APIs catkin LQ Suggestions & Feedback 6 02-17-2010 12:44 AM
LXer: The advantages of using public APIs like Google's with Ajax LXer Syndicated Linux News 0 01-25-2007 12:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration