Last active
December 18, 2015 21:29
-
-
Save brianfromoregon/5847903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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