Create empty spreadsheet in Google Docs via cURL and PHP

By : Marco

I am trying to create a new spreadsheet in Google docs without using the Zend library. I worked through the documentation and tried to follow the steps but now I am stuck. My code looks like this

    $curl = curl_init();

    $headers = array(
        "GData-Version: 3.0",
        "Authorization: GoogleLogin auth=" . $myToken,
        "Content-Length: 350",
        "Content-Type: application/atom+xml",
        "X-Upload-Content-Length: 0"

    $post_field = '<?xml version="1.0" encoding="UTF-8"?>
        <entry xmlns="" xmlns:docs="">
        <category scheme=""

    curl_setopt($curl, CURLOPT_URL, '');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_field);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);      

    $response = curl_exec($curl);

The token seems to be working fine since I am able to use it to retrieve data from google docs. What surprises me is that I don't get a response from the API. While trying out different solutions I usually got an error message, but here the response string is empty.

By : Marco


If you can, you should use the files.insert method of the Google Drive API instead.

This video can help you solving your question :)
By: admin