gpt4 book ai didi

android - 无法通过我的 Android 应用程序访问我的 Google 电子表格

转载 作者:行者123 更新时间:2023-11-30 01:56:30 25 4
gpt4 key购买 nike

各位!

我正在编写一个 Android 应用程序,它从 Google 电子表格(已发布到网络)下载数据,我已经在其中插入了 3 行以进行测试。我使用 json 格式的 url 链接到电子表格,以便我直接以 json 格式下载电子表格。当我在浏览器中输入 url 时,我得到了 json 格式的电子表格:

    /*O_o*/
google.visualization.Query.setResponse({"version":"0.6","reqId":"0","status":"ok","sig":"270757910","table":{"cols":[{"id":"A","label":"ID\n","type":"number","pattern":"General"},{"id":"B","label":"Title","type":"string"},{"id":"C","label":"Description","type":"string"},{"id":"D","label":"Picture","type":"string"},{"id":"E","label":"Date","type":"string"},{"id":"F","label":"Time","type":"string"},{"id":"G","label":"Author","type":"string"},{"id":"H","label":"Category","type":"string"}],"rows":[{"c":[{"v":1.0,"f":"1"},{"v":"title1"},{"v":"description1"},{"v":"picture1"},{"v":"date1"},{"v":"time1"},{"v":"author1"},{"v":"category1"}]},{"c":[{"v":2.0,"f":"2"},{"v":"title2"},{"v":"description2"},{"v":"picture2"},{"v":"date2"},{"v":"time2"},{"v":"author2"},{"v":"category2"}]},{"c":[{"v":3.0,"f":"3"},{"v":"title3"},{"v":"description3"},{"v":"picture3"},{"v":"date3"},{"v":"time3"},{"v":"author3"},{"v":"category3"}]}]}});

但是当我尝试使用此 url 通过应用程序下载它并记录结果时,我得到了这个:

08-20 15:45:51.706: D/test(14095):   <meta name="description" content="Create a new spreadsheet and edit with others at the same time -- from your computer, phone or tablet. Get stuff done with or without an internet connection. Use Sheets to edit Excel files. Free from Google.">
08-20 15:45:51.706: D/test(14095): <meta name="google-site-verification" content="LrdTUW9psUAMbh4Ia074-BPEVmcpBxF6Gwf0MSgQXZs">
08-20 15:45:51.706: D/test(14095): <title>Google Sheets - create and edit spreadsheets online, for free.</title>
08-20 15:45:51.706: D/test(14095): <style>
08-20 15:45:51.706: D/test(14095): @font-face {
08-20 15:45:51.706: D/test(14095): font-family: 'Open Sans';
08-20 15:45:51.706: D/test(14095): font-style: normal;
08-20 15:45:51.706: D/test(14095): font-weight: 300;
08-20 15:45:51.706: D/test(14095): src: url(//fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTZS3E-kSBmtLoNJPDtbj2Pk.ttf) format('truetype');
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): @font-face {
08-20 15:45:51.706: D/test(14095): font-family: 'Open Sans';
08-20 15:45:51.706: D/test(14095): font-style: normal;
08-20 15:45:51.706: D/test(14095): font-weight: 400;
08-20 15:45:51.706: D/test(14095): src: url(//fonts.gstatic.com/s/opensans/v13/cJZKeOuBrn4kERxqtaUH3SZ2oysoEQEeKwjgmXLRnTc.ttf) format('truetype');
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): </style>
08-20 15:45:51.706: D/test(14095): <style>
08-20 15:45:51.706: D/test(14095): h1, h2 {
08-20 15:45:51.706: D/test(14095): -webkit-animation-duration: 0.1s;
08-20 15:45:51.706: D/test(14095): -webkit-animation-name: fontfix;
08-20 15:45:51.706: D/test(14095): -webkit-animation-iteration-count: 1;
08-20 15:45:51.706: D/test(14095): -webkit-animation-timing-function: linear;
08-20 15:45:51.706: D/test(14095): -webkit-animation-delay: 0;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): @-webkit-keyframes fontfix {
08-20 15:45:51.706: D/test(14095): from {
08-20 15:45:51.706: D/test(14095): opacity: 1;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): to {
08-20 15:45:51.706: D/test(14095): opacity: 1;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): </style>
08-20 15:45:51.706: D/test(14095): <style>
08-20 15:45:51.706: D/test(14095): html, body {
08-20 15:45:51.706: D/test(14095): font-family: Arial, sans-serif;
08-20 15:45:51.706: D/test(14095): background: #fff;
08-20 15:45:51.706: D/test(14095): margin: 0;
08-20 15:45:51.706: D/test(14095): padding: 0;
08-20 15:45:51.706: D/test(14095): border: 0;
08-20 15:45:51.706: D/test(14095): position: absolute;
08-20 15:45:51.706: D/test(14095): height: 100%;
08-20 15:45:51.706: D/test(14095): min-width: 100%;
08-20 15:45:51.706: D/test(14095): font-size: 13px;
08-20 15:45:51.706: D/test(14095): color: #404040;
08-20 15:45:51.706: D/test(14095): direction: ltr;
08-20 15:45:51.706: D/test(14095): -webkit-text-size-adjust: none;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): button,
08-20 15:45:51.706: D/test(14095): input[type=button],
08-20 15:45:51.706: D/test(14095): input[type=submit] {
08-20 15:45:51.706: D/test(14095): font-family: Arial, sans-serif;
08-20 15:45:51.706: D/test(14095): font-size: 13px;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): a,
08-20 15:45:51.706: D/test(14095): a:hover,
08-20 15:45:51.706: D/test(14095): a:visited {
08-20 15:45:51.706: D/test(14095): color: #427fed;
08-20 15:45:51.706: D/test(14095): cursor: pointer;
08-20 15:45:51.706: D/test(14095): text-decoration: none;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): a:hover {
08-20 15:45:51.706: D/test(14095): text-decoration: underline;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): h1 {
08-20 15:45:51.706: D/test(14095): font-size: 20px;
08-20 15:45:51.706: D/test(14095): color: #262626;
08-20 15:45:51.706: D/test(14095): margin: 0 0 15px;
08-20 15:45:51.706: D/test(14095): font-weight: normal;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): h2 {
08-20 15:45:51.706: D/test(14095): font-size: 14px;
08-20 15:45:51.706: D/test(14095): color: #262626;
08-20 15:45:51.706: D/test(14095): margin: 0 0 15px;
08-20 15:45:51.706: D/test(14095): font-weight: bold;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=email],
08-20 15:45:51.706: D/test(14095): input[type=number],
08-20 15:45:51.706: D/test(14095): input[type=password],
08-20 15:45:51.706: D/test(14095): input[type=tel],
08-20 15:45:51.706: D/test(14095): input[type=text],
08-20 15:45:51.706: D/test(14095): input[type=url] {
08-20 15:45:51.706: D/test(14095): -moz-appearance: none;
08-20 15:45:51.706: D/test(14095): -webkit-appearance: none;
08-20 15:45:51.706: D/test(14095): appearance: none;
08-20 15:45:51.706: D/test(14095): display: inline-block;
08-20 15:45:51.706: D/test(14095): height: 36px;
08-20 15:45:51.706: D/test(14095): padding: 0 8px;
08-20 15:45:51.706: D/test(14095): margin: 0;
08-20 15:45:51.706: D/test(14095): background: #fff;
08-20 15:45:51.706: D/test(14095): border: 1px solid #d9d9d9;
08-20 15:45:51.706: D/test(14095): border-top: 1px solid #c0c0c0;
08-20 15:45:51.706: D/test(14095): -moz-box-sizing: border-box;
08-20 15:45:51.706: D/test(14095): -webkit-box-sizing: border-box;
08-20 15:45:51.706: D/test(14095): box-sizing: border-box;
08-20 15:45:51.706: D/test(14095): -moz-border-radius: 1px;
08-20 15:45:51.706: D/test(14095): -webkit-border-radius: 1px;
08-20 15:45:51.706: D/test(14095): border-radius: 1px;
08-20 15:45:51.706: D/test(14095): font-size: 15px;
08-20 15:45:51.706: D/test(14095): color: #404040;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=email]:hover,
08-20 15:45:51.706: D/test(14095): input[type=number]:hover,
08-20 15:45:51.706: D/test(14095): input[type=password]:hover,
08-20 15:45:51.706: D/test(14095): input[type=tel]:hover,
08-20 15:45:51.706: D/test(14095): input[type=text]:hover,
08-20 15:45:51.706: D/test(14095): input[type=url]:hover {
08-20 15:45:51.706: D/test(14095): border: 1px solid #b9b9b9;
08-20 15:45:51.706: D/test(14095): border-top: 1px solid #a0a0a0;
08-20 15:45:51.706: D/test(14095): -moz-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
08-20 15:45:51.706: D/test(14095): -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
08-20 15:45:51.706: D/test(14095): box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=email]:focus,
08-20 15:45:51.706: D/test(14095): input[type=number]:focus,
08-20 15:45:51.706: D/test(14095): input[type=password]:focus,
08-20 15:45:51.706: D/test(14095): input[type=tel]:focus,
08-20 15:45:51.706: D/test(14095): input[type=text]:focus,
08-20 15:45:51.706: D/test(14095): input[type=url]:focus {
08-20 15:45:51.706: D/test(14095): outline: none;
08-20 15:45:51.706: D/test(14095): border: 1px solid #4d90fe;
08-20 15:45:51.706: D/test(14095): -moz-box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
08-20 15:45:51.706: D/test(14095): -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
08-20 15:45:51.706: D/test(14095): box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=checkbox],
08-20 15:45:51.706: D/test(14095): input[type=radio] {
08-20 15:45:51.706: D/test(14095): -webkit-appearance: none;
08-20 15:45:51.706: D/test(14095): display: inline-block;
08-20 15:45:51.706: D/test(14095): width: 13px;
08-20 15:45:51.706: D/test(14095): height: 13px;
08-20 15:45:51.706: D/test(14095): margin: 0;
08-20 15:45:51.706: D/test(14095): cursor: pointer;
08-20 15:45:51.706: D/test(14095): vertical-align: bottom;
08-20 15:45:51.706: D/test(14095): background: #fff;
08-20 15:45:51.706: D/test(14095): border: 1px solid #c6c6c6;
08-20 15:45:51.706: D/test(14095): -moz-border-radius: 1px;
08-20 15:45:51.706: D/test(14095): -webkit-border-radius: 1px;
08-20 15:45:51.706: D/test(14095): border-radius: 1px;
08-20 15:45:51.706: D/test(14095): -moz-box-sizing: border-box;
08-20 15:45:51.706: D/test(14095): -webkit-box-sizing: border-box;
08-20 15:45:51.706: D/test(14095): box-sizing: border-box;
08-20 15:45:51.706: D/test(14095): position: relative;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=checkbox]:active,
08-20 15:45:51.706: D/test(14095): input[type=radio]:active {
08-20 15:45:51.706: D/test(14095): background: #ebebeb;
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=checkbox]:hover {
08-20 15:45:51.706: D/test(14095): border-color: #c6c6c6;
08-20 15:45:51.706: D/test(14095): -moz-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
08-20 15:45:51.706: D/test(14095): -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
08-20 15:45:51.706: D/test(14095): box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
08-20 15:45:51.706: D/test(14095): }
08-20 15:45:51.706: D/test(14095): input[type=radio] {
08-20 15:45:51.706: D/test(14095): -moz-bo
08-20 15:45:51.708: D/test(14095): {"font-family":"Open Sans","src":"url(","font-weight":400,"font-style":"normal"}

这是我下载电子表格的代码:

public class DownloadWebpageTask extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... urls) {

try {
return downloadUrl(urls[0]);
} catch (IOException e) {
return "Unable to download the requested page.";
}
}

@Override
protected void onPostExecute(String result) {

Log.d("test", "String: " + result);
int start = result.indexOf("{", result.indexOf("{") + 1);
int end = result.lastIndexOf("}");
String jsonResponse = result.substring(start, end);
try {
JSONObject table = new JSONObject(jsonResponse);
} catch (JSONException e) {
e.printStackTrace();
}
}

private String downloadUrl(String urlString) throws IOException {
InputStream is = null;

try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
int responseCode = conn.getResponseCode();
is = conn.getInputStream();
String contentAsString = convertStreamToString(is);
return contentAsString;
} finally {
if (is != null) {
is.close();
}
}
}

private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();

String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}

我还没有完成代码,我只是想看看我的应用程序是否正确下载了 json 格式的电子表格。

我在这里卡了3天多了,还是没找到问题。

我会感谢我能得到的每一个帮助!

最佳答案

我不是一个人!

我创建了一个从 Google 电子表格中提取数据的仪表板。几个小时前,我尝试运行我的仪表板时收到大量错误,告诉我 JSON 格式存在问题。我看了一下,“/O_o/”出现在所有文件的顶部。

这一定是谷歌内部的变化,不管是有意还是无意,它都有望被改回来。

关于android - 无法通过我的 Android 应用程序访问我的 Google 电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32119825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com