【问题标题】:Delete Row in Google spredsheet with PHP & Curl使用 PHP 和 Curl 删除 Google 电子表格中的行
【发布时间】:2014-05-01 01:37:36
【问题描述】:

Google API 没有对 PHP 的内置支持(显然 Zend 框架集成不再受支持)。因此,我一直在使用 Curl 从电子表格中读取和写入。 Like This

我需要的大部分内容都可以在这里找到:https://developers.google.com/google-apps/spreadsheets/ 在“协议”标签下。

但是,我现在想删除一行,文档显示这样做:

删除 https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full/rowId/rowVersion

问题是Curl不支持delete。我通常使用POSTGET。如何通过 curl 发出这样的命令?还有其他方法可以通过 curl 删除列表行吗?

根据下面 jeroen 的回答,我尝试了以下方法:

$headers = array(
            "Authorization: GoogleLogin auth=" . $auth,
            "GData-Version: 3.0",
            );
        $curl = curl_init();
        $curl_setopt($curl, CURLOPT_URL, "https://spreadsheets.google.com/feeds/list/key/0/private/full/1a8lrz");
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
        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);
        curl_setopt($curl, CURLOPT_VERBOSE, true);
        $response = curl_exec($curl);

但我绝对没有得到任何回应,完全没有错误。我已完全启用错误报告,并且我用于身份验证的 $auth 变量适用于对此电子表格的其他调用

【问题讨论】:

    标签: php curl google-api google-spreadsheet-api


    【解决方案1】:

    您可以通过设置CURLOPT_CUSTOMREQUEST 选项使用curl 发出DELETE 请求,请参阅manual

     curl_setopt($your_curl_resource, CURLOPT_CUSTOMREQUEST, "DELETE");
    

    【讨论】:

    • 谢谢您,看来应该可以了,但没有按照我上面的更新。
    【解决方案2】:

    应该更仔细地阅读 Google 的文档。我在标题中添加了“if-match”:

    $headers = array(
                "Authorization: GoogleLogin auth=" . $auth,
                "GData-Version: 3.0",
                "If-Match: *",
                );
    

    奇怪的是,API 根本不返回任何响应 - 但它确实删除了正确的行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多