如何在 Android 模拟器上使用 google 电子表格 api

发布于 2024-09-18 09:29:29 字数 1705 浏览 2 评论 0原文

我正在尝试使用 Google Spreadsheet api 来更新工作表的单元格。 我按照指南尝试发送 HttpPut 请求来执行此操作,但失败了。

我从以下代码中得到 200 OK,但工作表中没有任何内容更新......TT

String cellUri = "https://spreadsheets.google.com/feeds/cells/tD0jOr1kFs6yHag573hB0YA/od6/private/full/R2C2";

     HttpPut httpput = new HttpPut(cellUri);

     httpput.addHeader( new BasicHeader("Content-Type", "application/atom+xml"));
     httpput.addHeader( new BasicHeader("GData-Version", "3.0"));
     httpput.addHeader( new BasicHeader("If-Match", "*"));

     String reqBody="<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">" +
       "<id>https://spreadsheets.google.com/feeds/cells/tD0jOr1kFs6yHag573hB0YA/od6/private/full/R2C2</id>" +
       "<link rel=\"edit\" type=\"application/atom+xml\" href=\"https://spreadsheets.google.com/feeds/cells/tD0jOr1kFs6yHag573hB0YA/od6/private/full/R2C2/a115r\"/>" +
       "<gs:cell row=\"2\" col=\"2\" inputValue='99999'/>" +
       "</entry>";

     try
     {
      httpput.setEntity( new StringEntity(reqBody));
   HttpResponse updateCellResponse = new DefaultHttpClient().execute(httpput);
   if( updateCellResponse.getStatusLine().getStatusCode() != 200)
    Log.i("html2", "sl : " + updateCellResponse.getStatusLine());

   //display toast notification
   Toast _toast = Toast.makeText(getApplicationContext(), updateCellResponse.getStatusLine().toString() , Toast.LENGTH_SHORT);
   _toast.show();
     }
     catch(ClientProtocolException e )
     {
      Log.i("html2", e.getMessage().toString());
     }
     catch(IOException e )
     {
      Log.i("html2", e.getMessage().toString());
     }

    }

I'm trying to use Google Spreadsheet api to update a cell of a worksheet.
I followed the guide , tried to send a HttpPut request to do that but failed.

i got 200 OK from the following Code, but nothing be updated in the worksheet........T.T

String cellUri = "https://spreadsheets.google.com/feeds/cells/tD0jOr1kFs6yHag573hB0YA/od6/private/full/R2C2";

     HttpPut httpput = new HttpPut(cellUri);

     httpput.addHeader( new BasicHeader("Content-Type", "application/atom+xml"));
     httpput.addHeader( new BasicHeader("GData-Version", "3.0"));
     httpput.addHeader( new BasicHeader("If-Match", "*"));

     String reqBody="<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">" +
       "<id>https://spreadsheets.google.com/feeds/cells/tD0jOr1kFs6yHag573hB0YA/od6/private/full/R2C2</id>" +
       "<link rel=\"edit\" type=\"application/atom+xml\" href=\"https://spreadsheets.google.com/feeds/cells/tD0jOr1kFs6yHag573hB0YA/od6/private/full/R2C2/a115r\"/>" +
       "<gs:cell row=\"2\" col=\"2\" inputValue='99999'/>" +
       "</entry>";

     try
     {
      httpput.setEntity( new StringEntity(reqBody));
   HttpResponse updateCellResponse = new DefaultHttpClient().execute(httpput);
   if( updateCellResponse.getStatusLine().getStatusCode() != 200)
    Log.i("html2", "sl : " + updateCellResponse.getStatusLine());

   //display toast notification
   Toast _toast = Toast.makeText(getApplicationContext(), updateCellResponse.getStatusLine().toString() , Toast.LENGTH_SHORT);
   _toast.show();
     }
     catch(ClientProtocolException e )
     {
      Log.i("html2", e.getMessage().toString());
     }
     catch(IOException e )
     {
      Log.i("html2", e.getMessage().toString());
     }

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文