Question

The Google API does not have built-in support for PHP (and apparently the Zend framework integration is no longer supported). I have therefore been using Curl to read and write from the spreadsheets. Like This

Most of what I need can be found here: https://developers.google.com/google-apps/spreadsheets/ under the 'protocol' tab.

However, I now want to delete a row and the documentation shows to do this:

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

Problem is that Curl does not support delete. I normally use POST or GET. How can I issue such a command via curl? Is there any other way to delete a list row via curl?

As per jeroen's answer below, I tried the following:

$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);

But I get absolutely no response, no errors at all. I have error reporting fully enabled and the $auth variable I am using for authentication works on other calls to this spreadsheet

Was it helpful?

Solution 2

Should have read Google's documentation more carefully. I added 'if-match' to the header:

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

Bizarre how the API returns no response at all - but it does delete the correct row.

OTHER TIPS

You can do a DELETE request with curl by setting the CURLOPT_CUSTOMREQUEST option, see the manual:

 curl_setopt($your_curl_resource, CURLOPT_CUSTOMREQUEST, "DELETE");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top