OK. The following code works for me.
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
// The Google Script URL
String googleAppsScriptURL = "https://script.google.com/macros/s/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o/dev";
HttpURLConnection connection = null;
try {
URL url = new URL(googleAppsScriptURL + "?param1=foo¶m2=bar");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", "Bearer " + sessionManager.getCredentials().getToken());
if(connection.getResponseCode() == 200) {
// DO STUFF
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GoogleAuthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(connection != null) {
connection.disconnect();
}
}
return null;
}
}.execute();
Calling connection.getResponseCode() is important to get the actual request going.
sessionManager.getCreadentials() is a Singleton Application class of mine that returns GoogleAccountCredential object, that is required for the oAuth2 Authentication process.
And finally this code will enter in doPost function in Google Scripts:
function doPost(e) {
if(typeof e !== 'undefined') {
Logger.log(e.parameters.param1); // foo
Logger.log( e.parameters.param2); // bar
callYourFunction(e.parameter.param1, e.parameter.param2);
}
}