从googlesheet到Android的JSON提供了垃圾
我在android应用程序中获得了一份来自谷歌表单的数据列表。Google脚本运行正常,测试运行也提供了正确的输出。然而,android应用程序中接收到的JSON数据看起来像垃圾。这是我的android端代码。我正在使用截击:从googlesheet到Android的JSON提供了垃圾,android,kotlin,google-apps-script,android-volley,google-sheets-api,Android,Kotlin,Google Apps Script,Android Volley,Google Sheets Api,我在android应用程序中获得了一份来自谷歌表单的数据列表。Google脚本运行正常,测试运行也提供了正确的输出。然而,android应用程序中接收到的JSON数据看起来像垃圾。这是我的android端代码。我正在使用截击: private fun getList() { val stringRequest = StringRequest( Request.Method.GET, "https://docs.google.com/spreadsheets/d/
private fun getList() {
val stringRequest = StringRequest(
Request.Method.GET, "https://docs.google.com/spreadsheets/d/***********/edit#gid=0",
Response.Listener<String> { response ->
Log.d("MyMessage", response)
parseItems(response)
},
Response.ErrorListener { responseEr -> }
)
val socketTimeOut = 500000
val policy = DefaultRetryPolicy(socketTimeOut, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
stringRequest.retryPolicy = policy
val queue = Volley.newRequestQueue(this)
queue.add(stringRequest)
}
但android应用程序中的响应日志提供以下输出:
<!DOCTYPE html>…
我在这里做错了什么这个返回:
[“COL2”,10,11,3,3,2,1,7,11,5,9,3,10]
从该表数据:
COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10,COL11,COL12
7,10,8,0,0,1,3,11,2,10,9,7
11,11,6,0,1,2,11,7,6,4,1,6
7,3,6,0,6,4,6,1,1,7,8,1
9,3,1,2,11,1,2,10,11,8,1,0
1,2,9,5,11,4,11,9,3,10,0,11
7,1,0,3,8,10,3,4,11,3,1,1
10,7,9,11,11,5,1,5,0,6,11,9
5,11,3,5,3,5,3,7,3,6,9,6
4,5,1,6,7,3,8,3,2,4,3,10
11,9,11,11,6,8,3,0,3,5,9,11
5,3,9,10,9,8,10,5,1,11,9,0
6,10,0,8,10,5,2,2,6,4,5,6
这个网址:
https://script.google.com/a/............/exec?action=getlist
这是gs代码:
function doGet(e){
if(e.parameter && e.parameter.action=='getlist') {
return getList();
}
}
function getList(){
var ss=SpreadsheetApp.openById('Spreasheet Id')
var sh=ss.getSheetByName('Sheet Name');
var vA=sh.getRange(1,2,sh.getLastRow(),1).getValues().map(function(r,i){return r[0]});
return ContentService.createTextOutput(JSON.stringify(vA));
}
Android应用程序没有足够的权限访问应用程序脚本web应用程序,并被重定向到Google的登录页面。一些解决方案包括:
- 将web应用访问权限减少为“任何人,甚至匿名”或
- 通过向Google和oauth注册来增加android应用程序的权限
- 或者,使用
https://script.google.com/a/............/exec?action=getlist
function doGet(e){
if(e.parameter && e.parameter.action=='getlist') {
return getList();
}
}
function getList(){
var ss=SpreadsheetApp.openById('Spreasheet Id')
var sh=ss.getSheetByName('Sheet Name');
var vA=sh.getRange(1,2,sh.getLastRow(),1).getValues().map(function(r,i){return r[0]});
return ContentService.createTextOutput(JSON.stringify(vA));
}