在Android中运行Google Apps脚本 [英] Run Google Apps Script in Android

查看:114
本文介绍了在Android中运行Google Apps脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

}

我不想使用Apps Script Execution Script API东西,因为它太麻烦了,而且只包含我的应用程序的一个小公园.另外,API密钥是我不想处理的东西.它应该返回一些错误(正确地输入正确的电话号码后返回未定义),但是我得到了随机HTML.这不能使用WebView.我需要以Java中的字符串形式获取结果.如果WebView是一个步骤,那就去吧.谢谢!

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!

推荐答案

使用ContentService代替HtmlService:

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

这篇关于在Android中运行Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆