I am trying to run an Apps Script script in Android. Here is my script: https://script.google.com/a/macros/hdsb.ca/s/AKfycbwSoiiutFyMT4Guo9M-It895ZqHzu5U-tP9BtnwfYx8/dev?phonenumber=whateverphonenumber. When I try to access it on Android through Volley, it breaks down, giving me some random HTML code, when I just want the result(plain text). Here is my method:
private void checkSheet(){ TelephonyManager tMgr = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); final String mPhoneNumber = tMgr.getLine1Number().split("'")[0]; // Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); final String url ="https://script.google.com/macros/s/AKfycbxDkrEaMvJRyT31_flpyb1N1pGG3HuvWQzMDq05JuREEXZdo048/exec?phonenumber="+mPhoneNumber; final String[] returnVal = new String[1]; // Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { // Display the first 500 characters of the response string. returnVal[0] = response.substring(0,1000); Log.v("MainActivity", "Recieved Volley request"); SharedPreferences sharedPreferences = getSharedPreferences("data", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("subNum", returnVal[0]); editor.apply(); Log.v("MainActivity", "Returned " + String.valueOf(returnVal[0])); Log.v("MainActivity", "Phone number is: " + mPhoneNumber); Log.v("MainActivity", "Send url is: " + url); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); // Add the request to the RequestQueue. queue.add(stringRequest); }
I don't want to use the Apps Script Execution Script API thingie because it is too cumbersome and this only consists of a small park of my app. Plus, API keys are something that I don't wanna deal with. It is supposed to return with some error(when done properly with right phone number, returns undefined), but I get random HTML. This cannot use WebView; I NEED to get the result as a String in Java. If WebView is a step, so be it. Thank you!