How to generate blank Google Sheets file using PHP cURL without external libraries

I’m attempting to generate a new Google Sheets document using raw PHP cURL requests instead of relying on third-party libraries like Zend. I’ve been going through Google’s API documentation but I’m running into issues with my implementation.

Here’s my current approach:

$ch = curl_init();

$request_headers = array(
    "GData-Version: 3.0",
    "Authorization: GoogleLogin auth=" . $authToken,
    "Content-Length: 320",
    "Content-Type: application/atom+xml",
    "X-Upload-Content-Length: 0"
);

$xml_data = '<?xml version="1.0" encoding="UTF-8"?>
    <entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007">
    <category scheme="http://schemas.google.com/g/2005#kind"
        term="http://schemas.google.com/docs/2007#spreadsheet"/>
    <title>NewSpreadsheet</title>
    </entry>';

curl_setopt($ch, CURLOPT_URL, 'https://docs.google.com/feeds/upload/create-session/default/private/full');
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
curl_close($ch);

My authentication token works properly since I can successfully fetch existing documents with it. The weird part is that I’m getting absolutely no response from the API call. Usually when something goes wrong I at least get an error message back, but this time the response is completely empty. Has anyone encountered this issue before?

Had the exact same problem! Your code’s using the old GData API that Google killed off years ago. That XML stuff stopped working around 2015 when they switched everything to REST. You need Google Sheets API v4 instead. Use https://sheets.googleapis.com/v4/spreadsheets with a POST request and JSON data like {"properties":{"title":"NewSpreadsheet"}}. Also switch your auth header to Bearer token format - ditch that old GoogleLogin method. I wasted hours getting empty responses until I figured out I was hitting dead endpoints. Reading might still work with some legacy operations, but creating sheets definitely needs the newer API.

yeah, those empty responses are super frustrating when ur debugging! you’re hitting a dead URL that google just ignores instead of giving u a proper 404. I switched from the old XML approach to the v4 API last month and it works perfectly with JSON requests.

You’re encountering a deprecated endpoint that has been inactive for years. The GData API you are using has been phased out, which explains the empty responses instead of actual error messages. Google no longer maintains those old endpoints, leading to silent failures.

I faced this same issue while migrating legacy code last year. You should switch to the Sheets API v4, which utilizes standard REST calls. Additionally, your authentication method needs to be updated to OAuth2 with Bearer tokens instead of the old GoogleLogin method.

The empty response indicates that the endpoint no longer exists, which is not helpful for debugging. Transition to the modern API for improved error handling and access to better documentation.