Create empty spreadsheet in Google Docs via cURL and PHP

By : Marco
Source: Stackoverflow.com
Question!

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="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>Mytitle</title>
        </entry>';

    curl_setopt($curl, CURLOPT_URL, 'https://docs.google.com/feeds/upload/create-session/default/private/full');
    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);
    curl_close($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


Answers

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