Tuesday, 20 August 2013

Having trouble authorizing request to google fusion tables api from java application

Having trouble authorizing request to google fusion tables api from java
application

I am writing a small java installed application, that will be run on a
desktop, to interact with a google fusion table and I keep getting a 401
unauthorized error. Here is the code I am using to connect to and query
the table:
/** Global instance of the HTTP transport. */
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static void insertData(String query) throws IOException {
BasicAuthentication credential = new BasicAuthentication(username,
password);
fusiontables = new Fusiontables.Builder(HTTP_TRANSPORT, JSON_FACTORY,
credential).setApplicationName(
"Google-FusionTablesSample/1.0").build();
Query q = fusiontables.query();
Sql sql = q.sql(query);
try {
sql.execute();
} catch (IllegalArgumentException e) {
}
}
The table was created in my account and I am using my account's username
and password, so I know it's not that I am using the wrong login info.
This is my first time doing anything with java and oauth so can anyone
help me figure out what I am doing wrong here?

No comments:

Post a Comment