Google电子表格API如何插入

Google电子表格API如何插入

本文介绍了Google电子表格API如何插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我只使用API​​从Google电子表格中检索数据,但我不确定如何插入数据。我已经看遍了,但没有一个例子足够清晰。

So far I've only used the API to retrieve data from a Google spreadsheet, but I'm not sure how to insert data. I've looked all over but none of the examples are clear enough.

为了检索数据,我所要做的就是构建一个URL并使用CURL在PHP中进行检索像这样:

For retrieving data, all I had to do was construct a URL and retrieve it using CURL in PHP like this:

    //Get spreadsheet data
    $headers = array(
        "Authorization: GoogleLogin auth=" . $auth,
        "GData-Version: 3.0",
        );
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://spreadsheets.google.com/tq?tqx=out:html&tq=select%20D%2C%20E%20where%20B%3D&key=1c1xxxxxxxxxxxxx
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1
    $response= curl_exec($curl);

,我如何构建一个类似的URL来插入?我想会有一个类似的URL可以使用。有人可以请我指出正确的方向吗?我在这里找不到关于它的信息

, how do I construct a similar URL to insert? I would think there would be a similar URL that can be used. Can someone please point me in the right direction? I could not find info about it here https://developers.google.com/chart/interactive/docs/querylanguage

推荐答案

好吧,没有答案,但是一些研究指出我要,点击添加列表行的协议链接,可以为我提供足够的线索来构建以下内容:

Well, no answers but some more research pointed me to https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds where clicking under the 'protocol' link of 'adding a list row' gave me enough clues to construct the following:

//create xml with each element representing a column header (note: for some reason the headers must only contain alphanumeric characters)
$xml = "
<entry xmlns='http://www.w3.org/2005/Atom'
    xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>
  <gsx:id>123</gsx:id>
  <gsx:status>123</gsx:status>
  <gsx:date>4/26/2014</gsx:date>
  <gsx:user>bob</gsx:user>
</entry>";

//set headers which includes auth from elsewhere in the code
$headers = array(
    "Authorization: GoogleLogin auth=" . $auth,
    "GData-Version: 3.0",
    "Content-Type: application/atom+xml",
    );

//post the xml. The key in the url is taken from the actual url when you view the sheet
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://spreadsheets.google.com/feeds/list/xxxxxxxxxxxxxxxkeyxxxxxxxxx/0/private/full");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, "$xml");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);

其他

这篇关于Google电子表格API如何插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 12:25