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?
You seem to be doing basic authentication (which is sending your username and password in clear with each request), that is not OAuth at all. I don't think the fusion table API supports basic auth.
This is the OAuth 2 documentation: https://developers.google.com/accounts/docs/OAuth2
Be very careful with your password, do not send it in API calls.