我正嘗試在Android中運行Apps腳本腳本。這是我的腳本:https://script.google.com/a/macros/hdsb.ca/s/AKfycbwSoiiutFyMT4Guo9M-It895ZqHzu5U-tP9BtnwfYx8/dev?phonenumber=whateverphonenumber。當我嘗試通過Volley在Android上訪問它時,它發生故障,給我一些隨機的HTML代碼,當我只想得到結果(純文本)時。這裏是我的方法:在Android中運行Google Apps腳本
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);
}
我不想使用Google Apps腳本執行腳本API的thingie,因爲它是太麻煩了,這隻能由我的應用程序的一個小公園。另外,API密鑰是我不想處理的。它應該返回一些錯誤(當正確的電話號碼完成,返回未定義),但我得到隨機的HTML。這不能使用WebView;我需要需要在Java中以String結果。如果WebView是一個步驟,那就這樣吧。謝謝!
當我嘗試訪問鏈接時,我需要「訪問鏈接的權限」。也許這就是問題所在?也許你需要改變你的訪問設置? –
不 - 任何人都可以使用它,這不是問題。錯誤是預期的,我只是想要純文本,當錯誤到來或不來時。 @JagannathanAlagurajan – Vicky
你的webapp發佈的設置是什麼?通常隨機的html是google認證頁面。 –