Skip to content

Instantly share code, notes, and snippets.

@brianfromoregon
Last active December 18, 2015 21:29
Show Gist options
  • Save brianfromoregon/5847903 to your computer and use it in GitHub Desktop.
Save brianfromoregon/5847903 to your computer and use it in GitHub Desktop.
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new GsonFactory();
InputStream p12File = getResources().openRawResource(R.raw.googleapi_privatekey);
PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(
SecurityUtils.getPkcs12KeyStore(), p12File, "notasecret",
"privatekey", "notasecret");
// service account credential (uncomment setServiceAccountUser for domain-wide delegation)
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceEmail)
.setServiceAccountScopes(Collections.singleton(FusiontablesScopes.FUSIONTABLES))
.setServiceAccountPrivateKey(privateKey)
.build();
fusiontables = new Fusiontables.Builder(httpTransport, jsonFactory, credential).setApplicationName(appName).build();
String message = messages[0];
double latitude = -30.231129;
double longitude = -137.549435;
if (message == null) {
message = "";
}
String batchCsv = String.format("%s\0%f,%f\0%s\n", message.replace("\"", "\"\""),
latitude, longitude, new DateTime(System.currentTimeMillis()));
System.out.println(batchCsv);
ByteArrayContent content = ByteArrayContent.fromString("application/octet-stream", batchCsv);
Fusiontables.Table.ImportRows cmd = fusiontables.table().importRows(tableId, content);
cmd.setDelimiter("\0");
FusiontablesImport result = cmd.execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment