Authorize Google API
We are using Apex Web Services and can successfully connect to certain google apis. However in the initial authorization process where the user authorizes the app in the Google environment, upon returning to the callback url, the user has to log in to the apex application again. Is there a secure way to keep the user in the same session so they don't have to login again. Tried setting the 'state=' param to the value of the current session ID, but don't see how to pass it back in the call back URL.
Thanks.
I would post my question here...
http://groups.google.com/group/codesite-discuss
Similar Messages
-
Direct Rest Call To Google Api
Hi, I am trying to get Calendar list from my Google account using WebClient class. It is throwing 401 unauthorized error. My login credentials are correct but can't figure out what is wrong in my code. Here the code I am using to access Google Calendar
Api. Please someone also tell me how to use auth token as I know how to generate token but don't know how to use it in Webclient Api Class. I searched everywhere in Google but can't find a single example of making direct REST call to google api.
var content = "";
try
var url = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
var synClient = new WebClient();
//string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + “:” + passWord)); this one did not work.
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("use" + ":" + "pass"));
synClient.Headers[HttpRequestHeader.Authorization] = "Basic" + credentials;
content = synClient.DownloadString(url);
Console.WriteLine(content.ToString());
}catch(WebException e)
Console.WriteLine(e.Message+" "+e.StackTrace);Hi, I am trying to get Calendar list from my Google account using WebClient class. It is throwing 401 unauthorized error. My login credentials are correct but can't figure out what is wrong in my code. Here the code I am using to access Google Calendar
Api. Please someone also tell me how to use auth token as I know how to generate token but don't know how to use it in Webclient Api Class. I searched everywhere in Google but can't find a single example of making direct REST call to google api.
var content = "";
try
var url = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
var synClient = new WebClient();
//string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + “:” + passWord)); this one did not work.
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("use" + ":" + "pass"));
synClient.Headers[HttpRequestHeader.Authorization] = "Basic" + credentials;
content = synClient.DownloadString(url);
Console.WriteLine(content.ToString());
}catch(WebException e)
Console.WriteLine(e.Message+" "+e.StackTrace);
Please check out the documentation
here. It explains how to use it. It has a form to test requests:
HTTP request
GET https://www.googleapis.com/calendar/v3/users/me/calendarList
https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list#examples
https://developers.google.com/google-apps/calendar/firstapp
You could using API directly too: http://www.codeproject.com/Articles/64474/How-to-Read-the-Google-Calendar-in-C -
How do I use doGoogleSearch to connect to Google API
Hello all,
I am trying to do my final year project and I am currently having trouble connecting to the Google API using doGoogleSearch. I dont know how to use http://api.google.com/GoogleSearch.wsdl to fill in the parameters for the doGoogleSearch and then I have to use the http://api.google.com/search/beta2 to connect to Google and perform the test. Any help would be appreciated or code or links
Thanks in advance rgds,
Tony
Here is my code so far...................................
package tony_buckley_project;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.net.URI;
import java.net.URLConnection;
import java.util.*;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import com.google.soap.search.GoogleSearch;
import com.google.soap.search.GoogleSearchResult;
import com.google.soap.search.GoogleSearchFault;
import com.google.soap.search.GoogleSearchResultElement;
import com.google.soap.search.*;
import javax.xml.soap.*;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.w3c.dom.*;
import java.io.FileInputStream;
import javax.xml.transform.stream.StreamSource;
import javax.xml.messaging.URLEndpoint;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.*;
* <p>Title: Mr. Tony Buckley</p>
* <p>Description: </p>
* <p>Copyright: Copyright Tony Buckley (c) 2004</p>
* <p>Company: Cork Institute of Technology </p>
* @[email protected]
* @version 1.0
public class Applet2 extends Frame implements WindowListener , ActionListener
TextField searchField;
Button search , quit;
Canvas0 canvas;
public Applet2()
super();
//Set up basic window
setTitle("Tony Buckley Final Year Project");
setBackground(Color.white);
setSize(500 , 400);
addWindowListener(this);
//Set up area with buttons
//Search button
Panel p1 = new Panel();
p1.setLayout(new FlowLayout());
searchField = new TextField("" , 15);
p1.add(searchField);
search = new Button("Search the web for results...");
p1.add(search);
search.addActionListener(this);
//Quit button
Panel p2 = new Panel();
p2.setLayout(new FlowLayout());
Button quit = new Button("Quit");
p2.add(quit);
quit.addActionListener(this);
//Set up search results area
Canvas0 canvas = new Canvas0();
add("Center" , canvas);
Panel p4 = new Panel();
p4.setLayout(new GridLayout(2 , 1));
p4.add(p1);
p4.add(p2);
add("South" , p4);
}//End of constructor method public Applet2()
public void doGoogleSearch()
String key;
String q;
int start;
int maxResults;
boolean filter;
String restrict;
boolean safeSearch;
String lr;
String ie;
String oe;
public static void main(String[] args)
Applet2 app = new Applet2();
app.setVisible(true);
public void actionPerformed(ActionEvent event)
//Deals with "Quit" button
if(event.getSource() == quit)
dispose();
System.exit(0);
else if(event.getSource() == search)
/* try
String suggestion = search_internet .doSpellingSuggestion(spellingRequest);
if(suggestion == null)
System.out.println("There is no spelling suggestion in the database");
else
System.out.println(suggestion);
int startResult = 100;
search_internet.setStartResult(startResult);
int maxResult = 5;
search_internet.setMaxResults(maxResult);
GoogleSearchResult result_search_internet = search_internet.doSearch();
GoogleSearchResultElement[] resultElements = result_search_internet.getResultElements();
int startIndex = result_search_internet.getStartIndex() - 1 - startResult;
int endIndex = result_search_internet.getEndIndex() - 1 - startResult;
for(int i = startIndex ; i <= endIndex; i ++)
GoogleSearchResultElement resultElement = resultElements[(i)];
String title = resultElement.getTitle();
String URL = resultElement.getURL();
System.out.println(title);
System.out.println(URL);
System.out.println("");
System.out.println("Start Index = " + result_search_internet.getStartIndex());
System.out.println("End Index = " + result_search_internet.getEndIndex());
System.out.println(result_search_internet.toString());
int numResults = result_search_internet.getEstimatedTotalResultsCount();
if(result_search_internet.getEstimateIsExact())
System.out.println("Number of results: " +numResults);
else
System.out.println("Estimated number of results: " +numResults);
//catch(GoogleSearchFault gsf)
// System.out.println("Google Search Fault: " +gsf.getMessage());
try
String myKey = "0RK+HoNQFHJlcbNPfxgBpcjESUWV96aO";
String wsdl = "http://api.google.com/GoogleSearch.wsdl";
String url = "http://api.google.com/search/beta2";
String ns1 = "urn:GoogleSearch";
String searchTerm;
searchTerm = "science fiction";
String spellingRequest = searchTerm;
//First create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();
//Create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
//Populate the message
SOAPElement bodyElement = body.addChildElement(envelope.createName("doGoogleSearch" , "ns1", ns1));
GoogleSearch search = new GoogleSearch();
search.setKey(myKey);
search.setQueryString(searchTerm);
//Save the message
message.saveChanges();
//Send the message and get a reply
//Set the destination
URLEndpoint destination = new URLEndpoint(url);
//Send the message
SOAPMessage reply = connection.call(message, destination);
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = reply.getSOAPPart().getContent();
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
//Close the connection
connection.close();
catch(Exception e)
System.out.println(e.getMessage());
}//End of method actionPerformed
public void windowClosing(WindowEvent event)
//Deals with the window closing
dispose();
System.exit(0);
}//End of method windowClosing
public void windowOpened(WindowEvent event)
public void windowIconified(WindowEvent event)
public void windowDeiconified(WindowEvent event)
public void windowClosed(WindowEvent event)
public void windowActivated(WindowEvent event)
public void windowDeactivated(WindowEvent event)
}//End of class Applet2
class Canvas0 extends Canvas
public Canvas0()
super();
public void paint(Graphics g)
Dimension d = getSize();
Font f1 = new Font("TimesRoman" , Font.PLAIN , 14);
Font f2 = new Font("TimesRoman" , Font.ITALIC , 14);
FontMetrics fm1 = g.getFontMetrics(f1);
FontMetrics fm2 = g.getFontMetrics(f2);
String s1 = "Hello , ";
String s2 = "World";
int w1 =fm1.stringWidth(s1);
int w2 =fm1.stringWidth(s2);
g.setColor(Color.GREEN);import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.net.URI;
import java.net.URLConnection;
import java.util.*;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import com.google.soap.search.GoogleSearch;
import com.google.soap.search.GoogleSearchResult;
import com.google.soap.search.GoogleSearchFault;
import com.google.soap.search.GoogleSearchResultElement;
import com.google.soap.search.*;
import javax.xml.soap.*;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.w3c.dom.*;
import java.io.FileInputStream;
import javax.xml.transform.stream.StreamSource;
import javax.xml.messaging.URLEndpoint;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.*;
Title: Mr. Tony Buckley
Description:
Copyright: Copyright Tony Buckley (c) 2004
Company: Cork Institute of Technology
* @[email protected]
http://beingaplayer.x314.co.uk
* @version 1.0
public class Applet2 extends Frame implements WindowListener , ActionListener
TextField searchField;
Button search , quit;
Canvas0 canvas;
public Applet2()
super();
//Set up basic window
setTitle("Tony Buckley Final Year Project");
setBackground(Color.white);
setSize(500 , 400);
addWindowListener(this);
//Set up area with buttons
//Search button
Panel p1 = new Panel();
p1.setLayout(new FlowLayout());
searchField = new TextField("" , 15);
p1.add(searchField);
search = new Button("Search the web for results...");
p1.add(search);
search.addActionListener(this);
//Quit button
Panel p2 = new Panel();
p2.setLayout(new FlowLayout());
Button quit = new Button("Quit");
p2.add(quit);
quit.addActionListener(this);
//Set up search results area
Canvas0 canvas = new Canvas0();
add("Center" , canvas);
Panel p4 = new Panel();
p4.setLayout(new GridLayout(2 , 1));
p4.add(p1);
p4.add(p2);
add("South" , p4);
}//End of constructor method public Applet2()
public void doGoogleSearch()
String key;
String q;
int start;
int maxResults;
boolean filter;
String restrict;
boolean safeSearch;
String lr;
String ie;
String oe;
public static void main(String[] args)
Applet2 app = new Applet2();
app.setVisible(true);
public void actionPerformed(ActionEvent event)
//Deals with "Quit" button
if(event.getSource() == quit)
dispose();
System.exit(0);
else if(event.getSource() == search)
/* try
String suggestion = search_internet .doSpellingSuggestion(spellingRequest);
if(suggestion == null)
System.out.println("There is no spelling suggestion in the database");
else
System.out.println(suggestion);
int startResult = 100;
search_internet.setStartResult(startResult);
int maxResult = 5;
search_internet.setMaxResults(maxResult);
GoogleSearchResult result_search_internet = search_internet.doSearch();
GoogleSearchResultElement[] resultElements = result_search_internet.getResultElements();
int startIndex = result_search_internet.getStartIndex() - 1 - startResult;
int endIndex = result_search_internet.getEndIndex() - 1 - startResult;
for(int i = startIndex ; i <= endIndex; i ++)
GoogleSearchResultElement resultElement = resultElements[(i)];
String title = resultElement.getTitle();
String URL = resultElement.getURL();
System.out.println(title);
System.out.println(URL);
System.out.println("");
System.out.println("Start Index = " + result_search_internet.getStartIndex());
System.out.println("End Index = " + result_search_internet.getEndIndex());
System.out.println(result_search_internet.toString());
int numResults = result_search_internet.getEstimatedTotalResultsCount();
if(result_search_internet.getEstimateIsExact())
System.out.println("Number of results: " +numResults);
else
System.out.println("Estimated number of results: " +numResults);
//catch(GoogleSearchFault gsf)
// System.out.println("Google Search Fault: " +gsf.getMessage());
try
String myKey = "0RK+HoNQFHJlcbNPfxgBpcjESUWV96aO";
String wsdl = "http://api.google.com/GoogleSearch.wsdl";
String url = "http://api.google.com/search/beta2";
String ns1 = "urn:GoogleSearch";
String searchTerm;
searchTerm = "science fiction";
String spellingRequest = searchTerm;
//First create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();
//Create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
//Populate the message
SOAPElement bodyElement = body.addChildElement(envelope.createName("doGoogleSearch" , "ns1", ns1));
GoogleSearch search = new GoogleSearch();
search.setKey(myKey);
search.setQueryString(searchTerm);
//Save the message
message.saveChanges();
//Send the message and get a reply
//Set the destination
URLEndpoint destination = new URLEndpoint(url);
//Send the message
SOAPMessage reply = connection.call(message, destination);
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = reply.getSOAPPart().getContent();
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
//Close the connection
connection.close();
catch(Exception e)
System.out.println(e.getMessage());
}//End of method actionPerformed
public void windowClosing(WindowEvent event)
//Deals with the window closing
dispose();
System.exit(0);
}//End of method windowClosing
public void windowOpened(WindowEvent event)
public void windowIconified(WindowEvent event)
public void windowDeiconified(WindowEvent event)
public void windowClosed(WindowEvent event)
public void windowActivated(WindowEvent event)
public void windowDeactivated(WindowEvent event)
}//End of class Applet2
class Canvas0 extends Canvas
public Canvas0()
super();
public void paint(Graphics g)
Dimension d = getSize();
Font f1 = new Font("TimesRoman" , Font.PLAIN , 14);
Font f2 = new Font("TimesRoman" , Font.ITALIC , 14);
FontMetrics fm1 = g.getFontMetrics(f1);
FontMetrics fm2 = g.getFontMetrics(f2);
String s1 = "Hello , ";
String s2 = "World";
int w1 =fm1.stringWidth(s1);
int w2 =fm1.stringWidth(s2);
g.setColor(Color.GREEN); -
How to integrate Google api's in visual composer v 7.1 ehp1
Hi all,
I have tried the procedure given in the blog
/people/jakob.diness2/blog/2008/04/10/visual-composer-demo--customer-and-google-api
Where do i need to save the jsp file in the portal and how?
I have also tried doing the same in the follwoing blog
/people/vivekkumar.mishra2/blog/2008/03/03/visual-composer71-and-yahoo-maps--part-i
But when when i deploy it i get an exception
"java.net.MalformedURLException: Illegal character in fragment at index 33 "
Error details:
com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Invalid URL=http://maps.yahoo.com/#q1=hauptstrasse 2,Neu Ulm,Germany. See nested exception for details. Please check whether the URL contains query parameters which are not allowed for security reasons. See SAP note 864842 for more details
Can any one give a detailed solution?
Regards
TekumallaHi Deepa,
I'm assuming you would like to embed a map into your application.
In that case, you need to connect your data service (the one that holds the addresses you wish to present using the map) to an HTML view and map the data as follows:
="http://www.map-generator.net/map.php?name=spot&address="&@Address&"&city="&@City&"width=500&height=400&maptype=map&zoom=14"
Where @Address is the field in your service which holds the address, e.g: 10 market st
and the @City is the field in your service that hods the city, e.g: San Francisco
Hope this helps
Regards
Yogev -
Error in Receiver Soap Adapter for Google API
Hi,
I am working on HTTP-XI-Soap scenario which on the receiver side calls google API for spell check.
I get the following error : <b>No Deserializer found to deserialize a ':key' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'.</b>
However if I try calling the webservice individually using SOAP Client it works fine and do get desired response.The soap message that is sent by the client to the target URL is :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:GoogleSearch" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<urn:doSpellingSuggestion soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="xsd:string">qXWD4x1QFHIo/dePqlYOLwT7kMmkv80E</key>
<phrase <b>xsi:type="xsd:string"</b>>Bratney</phrase>
</urn:doSpellingSuggestion>
</soapenv:Body>
</soapenv:Envelope>
However if i remove the "xsi:type="xsd:string" part from the element 'phrase' and 'key' it returns the same error as it does while using with XI.
Hence I am assuming that that the outgoing soap message elements need to have the above highlighed attribute.
Now I want to have this attribute(xsi:type="xsd:string) in the soap message that is sent from XI.
My question is , Is there any setting using which I can add the attributes in the above form to the outgoing message from XI.I do not want to use a adapter Module.
Thanks & Regards,
SidharthHi Sidharth,
You post here the soap message that is sent by the client to the target URL, but did you look to the soap message that is sent by XI?
Try the AF monitor http://<host>:<j2ee-port>//MessagingSystem/monitor/monitor.jsp?
Because XI soap adapter doesn't support all tags of wsdl rpc-based, we need to adjust them...
Look to the SOAP FAQ (SAP note number 856597) under question "Can I convert an RPC styled WSDL to a document styled WSDL?"... Look at last but one paragraph ;o)
So, you need to change this attribute to one that it is compatible...
Go to http://service.sap.com/xi > Media Library > Documentation and there you will find this xls document -> SAP XI 3.0 (SP11) - Supported XML Schema and WSDL (EN) in this document you have all the compatible elements of wsdl for XI.
One more thing, you can adjust your soap request and change or add the required tags You can do it with xslt-mapping or create your won data types in XI without import the WSDL generated by google.
Hope it helps,
Ricardo.
Message was edited by: Ricardo Quintino -
REST Web Service References: Can't run Google APIS
Hello Everyone!
I am learning on how to integrate REST web service reference in APEX application. I found a tutorial video at YouTube on 'Creating and Using a RESTful Web Service in Application Express 4.2', which found to be very helpful and easy to do on my sample app. The REST Web Service URL:
http://maps.googleapis.com/maps/api/geocode/xml?address=san%20fancisco&sensor=false
But my application throws an error as below:
1 error has occurred
ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1130 ORA-24247: network access denied by access control list (ACL)
After going through some of the posts here at OTN, I have granted access as follows:
GRANT EXECUTE ON SYS.UTL_HTTP TO ETI;
GRANT EXECUTE ON SYS.UTL_INADDR TO ETI;
GRANT EXECUTE ON SYS.UTL_TCP TO ETI;
GRANT EXECUTE ON SYS.UTL_SMTP TO ETI;
GRANT EXECUTE ON SYS.UTL_URL to ETI;
GRANT EXECUTE ON SYS.UTL_XML to ETI;
Second thing I did was, created and assigned ACL:
begin
dbms_network_acl_admin.create_acl (
acl => 'googleapis.xml',
description => 'Google Translate API',
principal => 'CONNECT',
is_grant => true,
privilege => 'connect',
start_date => null,
end_date => null
dbms_network_acl_admin.add_privilege (
acl => 'googleapis.xml',
principal => 'CONNECT',
is_grant => true,
privilege => 'connect'
dbms_network_acl_admin.assign_acl (
acl => 'googleapis.xml',
host => 'ajax.googleapis.com'
dbms_network_acl_admin.assign_acl (
acl => 'googleapis.xml',
host => 'maps.googleapis.com'
end;
All these statements were executed on my database with out any error, even though not helping my web service reference to work.
Any idea how can I get my Google API REST Web service working, what is the thing I'm missing here?I apologize for the lack of information.
I thought I had included a list of schemas for you to try out.
At first, (due to the GRANT ___ TO ETI;) I thought you were writing your own Web Service parser in PL/SQL.
(If that was the case, than ETI would need be part with the ACL)
Then, I realized,you were using the built in APEX functionality.
In this case, try adding your APEX_{version} schema as part of the ACL.
I'm not sure if this will work (I haven't tried it).
However, I do know you need to add the APEX_{version} to the ACL if you use the LDAP Authentication.
finding APEX_{version}
select comp_id, version, status, schema
from dba_registry
where comp_id='APEX'
MK -
Need help using doGoogleSearch to connect to Google API
Hello all,
I am trying to do my final year project and I am currently having trouble connecting to the Google API using doGoogleSearch. I dont know how to use http://api.google.com/GoogleSearch.wsdl to fill in the parameters for the doGoogleSearch and then I have to use the http://api.google.com/search/beta2 to connect to Google and perform the test. Any help would be appreciated or code or links
Thanks in advance rgds,
Tony
Here is my code so far...................................
package tony_buckley_project;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.net.URI;
import java.net.URLConnection;
import java.util.*;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import com.google.soap.search.GoogleSearch;
import com.google.soap.search.GoogleSearchResult;
import com.google.soap.search.GoogleSearchFault;
import com.google.soap.search.GoogleSearchResultElement;
import com.google.soap.search.*;
import javax.xml.soap.*;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.w3c.dom.*;
import java.io.FileInputStream;
import javax.xml.transform.stream.StreamSource;
import javax.xml.messaging.URLEndpoint;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.*;
* <p>Title: Mr. Tony Buckley</p>
* <p>Description: </p>
* <p>Copyright: Copyright Tony Buckley (c) 2004</p>
* <p>Company: Cork Institute of Technology </p>
* @[email protected]
* @version 1.0
public class Applet2 extends Frame implements WindowListener , ActionListener
TextField searchField;
Button search , quit;
Canvas0 canvas;
public Applet2()
super();
//Set up basic window
setTitle("Tony Buckley Final Year Project");
setBackground(Color.white);
setSize(500 , 400);
addWindowListener(this);
//Set up area with buttons
//Search button
Panel p1 = new Panel();
p1.setLayout(new FlowLayout());
searchField = new TextField("" , 15);
p1.add(searchField);
search = new Button("Search the web for results...");
p1.add(search);
search.addActionListener(this);
//Quit button
Panel p2 = new Panel();
p2.setLayout(new FlowLayout());
Button quit = new Button("Quit");
p2.add(quit);
quit.addActionListener(this);
//Set up search results area
Canvas0 canvas = new Canvas0();
add("Center" , canvas);
Panel p4 = new Panel();
p4.setLayout(new GridLayout(2 , 1));
p4.add(p1);
p4.add(p2);
add("South" , p4);
}//End of constructor method public Applet2()
public void doGoogleSearch()
String key;
String q;
int start;
int maxResults;
boolean filter;
String restrict;
boolean safeSearch;
String lr;
String ie;
String oe;
public static void main(String[] args)
Applet2 app = new Applet2();
app.setVisible(true);
public void actionPerformed(ActionEvent event)
//Deals with "Quit" button
if(event.getSource() == quit)
dispose();
System.exit(0);
else if(event.getSource() == search)
/* try
String suggestion = search_internet .doSpellingSuggestion(spellingRequest);
if(suggestion == null)
System.out.println("There is no spelling suggestion in the database");
else
System.out.println(suggestion);
int startResult = 100;
search_internet.setStartResult(startResult);
int maxResult = 5;
search_internet.setMaxResults(maxResult);
GoogleSearchResult result_search_internet = search_internet.doSearch();
GoogleSearchResultElement[] resultElements = result_search_internet.getResultElements();
int startIndex = result_search_internet.getStartIndex() - 1 - startResult;
int endIndex = result_search_internet.getEndIndex() - 1 - startResult;
for(int i = startIndex ; i <= endIndex; i ++)
GoogleSearchResultElement resultElement = resultElements[(i)];
String title = resultElement.getTitle();
String URL = resultElement.getURL();
System.out.println(title);
System.out.println(URL);
System.out.println("");
System.out.println("Start Index = " + result_search_internet.getStartIndex());
System.out.println("End Index = " + result_search_internet.getEndIndex());
System.out.println(result_search_internet.toString());
int numResults = result_search_internet.getEstimatedTotalResultsCount();
if(result_search_internet.getEstimateIsExact())
System.out.println("Number of results: " +numResults);
else
System.out.println("Estimated number of results: " +numResults);
//catch(GoogleSearchFault gsf)
// System.out.println("Google Search Fault: " +gsf.getMessage());
try
String myKey = "0RK+HoNQFHJlcbNPfxgBpcjESUWV96aO";
String wsdl = "http://api.google.com/GoogleSearch.wsdl";
String url = "http://api.google.com/search/beta2";
String ns1 = "urn:GoogleSearch";
String searchTerm;
searchTerm = "science fiction";
String spellingRequest = searchTerm;
//First create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();
//Create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
//Populate the message
SOAPElement bodyElement = body.addChildElement(envelope.createName("doGoogleSearch" , "ns1", ns1));
GoogleSearch search = new GoogleSearch();
search.setKey(myKey);
search.setQueryString(searchTerm);
//Save the message
message.saveChanges();
//Send the message and get a reply
//Set the destination
URLEndpoint destination = new URLEndpoint(url);
//Send the message
SOAPMessage reply = connection.call(message, destination);
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = reply.getSOAPPart().getContent();
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
//Close the connection
connection.close();
catch(Exception e)
System.out.println(e.getMessage());
}//End of method actionPerformed
public void windowClosing(WindowEvent event)
//Deals with the window closing
dispose();
System.exit(0);
}//End of method windowClosing
public void windowOpened(WindowEvent event)
public void windowIconified(WindowEvent event)
public void windowDeiconified(WindowEvent event)
public void windowClosed(WindowEvent event)
public void windowActivated(WindowEvent event)
public void windowDeactivated(WindowEvent event)
}//End of class Applet2
class Canvas0 extends Canvas
public Canvas0()
super();
public void paint(Graphics g)
Dimension d = getSize();
Font f1 = new Font("TimesRoman" , Font.PLAIN , 14);
Font f2 = new Font("TimesRoman" , Font.ITALIC , 14);
FontMetrics fm1 = g.getFontMetrics(f1);
FontMetrics fm2 = g.getFontMetrics(f2);
String s1 = "Hello , ";
String s2 = "World";
int w1 =fm1.stringWidth(s1);
int w2 =fm1.stringWidth(s2);
g.setColor(Color.GREEN);I don't know where you got the rest of this code from (was it supplied as part of the project or did you write it yourself), but I think it may be overcomplicated.
The last time (at least a year ago) that I looked at the Google WS api, this is all you needed:
GoogleSearch search = new GoogleSearch();
search.setKey("_your_key_here_");
search.setQueryString(searchStringHere);
GoogleSearchResult result = search.doSearch();You can look in their api docs for how to extract the results from GoogleSearchResult.
Hope that helps?
Kevin Hooke -
Parsing HTML from Google API results
Hello,
I just downloaded the Google API (http://www.google.com/apis) and I am trying to parse the HTML content which is returned so that it can be displayed in a TextArea or some other GUI component.
Here are my questions:
1. Is there a Java class that can parse HTML and display it correctly?
2. If not, are there are third party, prefabably free Java components that can do that?
3. Has anyone tried out the Google API? Any interesting applications?
Thank you.
HanxueTo convert plain text to html, you can parse the text with a simple code like this
1.
String inputText = getInputText(); //
StringBuffer HTMLOutputText = new StringBuffer();
java.util.StringTokenizer st = new java.util.StringTokenzier(inputText, "\n\r");
while ( st.hasMoreTokens() ) {
HTMLOutputText.append(st.nextToken());
HTMLOutputText.append("<br>");
/// insert the top level HTML tags
HTMLOutputText.insert(0, "<HTML> <HEAD><TITLE> Some Title</TITLE></HEAD> <BODY>");
HTMLOutputText.insert( HTMLOutputText.getLength(), "</BODY> </HTML>" );
2. even simpler, but as far as I know it doesn't display right in a JEditorPane
String inputText = getInputText();
inputText = "<HTML> <HEAD><TITLE> Some Title</TITLE></HEAD> <BODY> <PRE> <TT>" +
+ inputText + "</TT></PRE></BODY> </HTML>"; -
Hi All,
I don't whether it is right place to post this question, but would like to know that has anyone used Google adWords api?
I am trying to develop an application using Google adWords apis and sandbox utility. But my application is throwing following exception.
Exception in thread "main" javax.xml.rpc.ServiceException: java.lang.ClassCastException: com.google.api.adwords.v10.CampaignServiceSoapBindingStub
please help me out.
Thanks in advance.Santosh,
Sorry but you have posted to a forum that deals exclusively with questions/issues about Microsoft Project, a planning and scheduling application. I suggest you delete this post and find a more appropriate forum.
John -
Usage of Google API for route implementation in the iPhone application
Hi,
We need to show the maps showing some specific locations and the routes from user's current location to these specific locations. We know that Google provides APIs for getting the route between two locations.
Google has some terms and conditions for using their APIs for route. You can find it on the website http://code.google.com/intl/de/apis/maps/iphone/terms.html (point 10.9).
Can anyone please advice if we can use Google APIs in our iPhone application?
Regards,
NileshThis is a user to user help forum for iPhone users, not for app developers with app development questions. As a registered iOS app developer with Apple, you have access to Apple's developer discussions area which is where such a question should be asked.
-
Hi,
I'm newbie to the portal technology and more worked on the EJB side.
My requirement is like this:
I've to display a world map and support the various events like mouse click, mouse hover etc.+
Google API can be used for this.
I've to fetch the data according to the events on the map. The next layer in the application has tight interface with Portal.
<ol><li> How can I display and handle world map events using portal?</li>
<li> If I use GoogleAPI, how should be both GoogleAPI and portal fit together?</li>
</ol>
Thanks in Advance,
Anaghashould be the same as any other mashup. Peter Laird has some entries regarding this
http://www.oracle.com/technology/pub/articles/dev2arch/2007/05/google-mashups2.html (here you'd use bea for your rest service)
and you can also visit
http://wlp.bea.com and click web 2.0
You'd use google api's just as you would in any other HTML page (in this case generated partly by the portlet hosting your code)
regards
deepak -
How streaming an audio or video files from google drive using google api objective-c client?
I have implemented streaming an audio or video files by mpmovieplayer from Dropbox. For this purpose I am using Dropbox sdk. Audio or video files are playing with no problem from dropbox in my app.
But, I can not implement the same functionality from Google drive. I am using alternateLink,webcontentLink,EmbedLink,Exportlink that we get from google drive. But mpmovieplayer does not play audio or video. So how can get any link from google drive,by which i can streaming an audio or video file from google drive. I have listed all google drive files in a table view. I am using google api objective-c client. So please help me. Thanks in advance.Hello,
I'm giving a try at your application and so far, it is great!
I understand that you're working on a way to help moving back files to google drive. Actually, I can copy / paste, but it always renames the files, so I end up with both a "copy of" and my original file.
could you save and overwite the original file when it already exists ? (perhaps an option in the settings) ?
Thanks! -
How to use Google API for Visual Studio Application using Google Drive
I am creating an VB 2010 Form that will collect data and then automate sharing to select individuals. Right now I am storing the data in the Google Drive folder on the Desktop but some people that may be using this application may not have Google Drive downloaded
on their desktop so I would like to know if there is another way to add the data files (Excel files) to Google Drive. I would also like to have my application automatically share the files with select individuals and possibly publish onto Google+ or at
least create a notification on Google+ that a new file has been added to the Drive. Thanks in advance for ANY help that anyone can offer!Hello,
Thank you for your post.
I am afraid that the issue is out of support range of VS General Question forum which mainly discusses
the usage of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
and Visual Studio Editor.
Because you use Google Drive and Google API which are third-party, I suggest consult on its support forum/community provided by its publisher.
IN addition, about Visual Basic programming, please consult on Visual Basic forum:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral for better response.
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Hi,
I have to post a file using this google API
https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/uploads/uploadData#try-it
How I will call this in PLSQL?
thanks,
7ZYou're retrieving a text containing character entity references.
UTL_I18N.UNESCAPE_REFERENCE will take care of getting back the original characters :
SQL> set scan off
SQL>
SQL>
SQL> SELECT utl_i18n.unescape_reference(
2 REGEXP_SUBSTR(tr,'<span id=result_box class="short_text"><span[^>]*>(.*)</span></span>',1,1,'i',1)
3 ) translated_value
4 FROM (
5 SELECT httpuritype('http://translate.google.com/?hl=en&layout=1&eotf=1&sl=en&tl='||'vi'||'&text='||
6 UTL_URL.escape('My text to be converted')|| '#').getclob() tr
7 FROM DUAL
8 );
TRANSLATED_VALUE
Văn bản của tôi được chuyển đổi -
Need to Use google APIs in View .htm Page
Hi Experts,
I have the following requirements:
I need to capture the Geo code based on the user click from Google maps and update the same in the CRM.
I need to load the Google maps with multiple Location Marking and Marking Icons will be changing based on some condition.
I had implemented the Mash-ups to Load Google Maps in the WEB UI screen.
I found that Mash-ups will be helpful only to load the web Page Via URL(parameters passing) and it will not return back any info.
So i created a custom view and write the Java Script logic which contain the Google APIs,functions to load the Maps dynamically with
multiple Geocodes Etc., How ever while am loading the view in the CRM am not able to load the maps.
So I create a Page with Flow Logic in the same BSP Component and i provide the same code which i given in View's .htm page,while testing its working fine.
Q1 > Using Mashups in CRM can use the Google APIS and can we raise events on click on the Maps?
Q2> Why Java Scripts contain Google APIS are not loading in the View's .htm page like Pages with flow Logic.
Q3> How can i Load the Page with flow Logic in the View's .htm page with out using Iframe?
Any Suggestion will be helpful.
Thanks and Regards,
Y. Ravi Kumar.Hi,
I just wanted to post some of my experience on java.nio.channels.FileLock.
If a file is in use by an application, for example if a jar file is launched, the file is obviously locked by the system in a way we can't delete it.
However it is still considered as unlocked by java as an exclusive FileLock could be set.
If an exclusive FileLock has been set on a file no other exclusive FileLock could be set by any other application. (relieved ! the basic lock operation works !)
When a FileLock is set on a jar file it DEFINITELY corrupt the considered jar !!!!!
the message "Invalid or corrupt jarfile" is displayed when I try to execute it using java
and any zip utility can't open it any more.
And it is not a locking problem !
Even after the exit of the application that lock the file, release of the lock, copy of the considered jar, the jarfile is definitely corrupted.
I guess it could/should be the same thing on other file types.
What an awful bug :(
My config is Windows Vista sp1
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
Considering the question "if I then use a FileLock and lock my file, can I still delete it?"
The answer is no you can't delete it:
You can't delete it with the application that locked it
(not even with File.deleteOnExit() method -- still with the above config --)
neither with another application.
Of course you can release the lock and delete it ...
Maybe you are looking for
-
hi i have a ipod touch 4 generation 64gb and my camera is blocked and dose not work i cant update the ipod either
-
HI all, How to write select query in SECATT test script?
-
Vudu requires Adobe Flash Player for movies and gives me an error message saying that I need to update to the newest version and gives a link. When i follow the link and install the newest version I still get the same message. I checked add-ons Firef
-
Which is more efficient way to get result set from database server
Hi, I am working on a project where I require to query database to fetch result set and then iterate through the resultset. Now, What I want is that I want to create one single java code that would call many different SQLs and create a list out of re
-
Network Management Software for MF4890dw?
We recently installed a bunch of MF4890dw multifunction printer/copier/scanners on our office. Is there an easy way to manage these over the network? I know I can access each one individually through its IP address, but the amount of control is lim