运行 Google Android 中的 Apps 脚本

Run Google Apps Script in Android

我正在尝试 运行 Android 中的 Apps Script 脚本。这是我的脚本:https://script.google.com/a/macros/hdsb.ca/s/AKfycbwSoiiutFyMT4Guo9M-It895ZqHzu5U-tP9BtnwfYx8/dev?phonenumber=whateverphonenumber。当我尝试通过 Volley 在 Android 上访问它时,它崩溃了,给了我一些随机的 HTML 代码,而我只想要结果(纯文本)。这是我的方法:

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);

}

我不想使用 Apps 脚本执行脚本 API 东西,因为它太麻烦了,而且它只包含我的应用程序的一小部分。另外,API 键是我不想处理的东西。它应该 return 有一些错误(当使用正确的 phone 数字正确完成时,returns 未定义),但我得到随机 HTML。这个不能用WebView;我需要 来获得 Java 中的字符串形式的结果。如果 WebView 是一个步骤,那就这样吧。谢谢!

使用 ContentService 而不是 HtmlService:https://developers.google.com/apps-script/guides/content。感谢 Spencer Easton。