Run Google Apps Script in Android

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

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!

回答1:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!