使用PHP删除Google电子表格中的行;卷曲

时间:2014-05-01 01:37:36

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

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

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

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

  

DELETE   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变量适用于此电子表格的其他调用

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

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

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