0

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!

  • When I try to access the link, I get need "permission to access the link." Perhaps that's the problem? Maybe you need to change your access settings? – Jack Brown Feb 12 '17 at 23:30
  • No-Anyone can use it, and that is not the problem. The error is expected, I just want the plain text, when the error comes or doesn't come. @JagannathanAlagurajan –  Feb 13 '17 at 11:43
  • What are your webapp published settings? Usually random html is the google authentication page. – Spencer Easton Feb 13 '17 at 14:45
  • I don't think you understand... when I am accessing it through Volley, it is giving me HTML. The HTML is the same thing that I see when I click 'view page source' in Chrome. @SpencerEaston –  Feb 14 '17 at 16:45
  • Show your apps script code. Just from looking at the returned error of your script you are uing the htmlservice not contentservice. If you want plain text you need to use contentservice. – Spencer Easton Feb 14 '17 at 20:53
  • Could you tell me how to use ContentService instead? Or do you really need my apps script code. @SpencerEaston –  Feb 15 '17 at 11:49
  • https://developers.google.com/apps-script/guides/content – Spencer Easton Feb 15 '17 at 18:03
  • Thank you. I will put it as an answer and mark it correctly. You can post your own answer and I will delete mine and check yours. @SpencerEaston –  Feb 26 '17 at 17:44

1 Answers1

0

Use ContentService instead of HtmlService: https://developers.google.com/apps-script/guides/content . Credit goes to Spencer Easton.