0

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.

2
  • What is the HTTP response code you receive? (var_dump(curl_getinfo($curl, CURLINFO_HTTP_CODE));) Commented Jul 4, 2012 at 10:12
  • I get a status code of 200, so the request was successful. The request code I am looking for is 201 Commented Jul 4, 2012 at 10:18

2 Answers 2

2

You are sending a request to initiate a resumable upload session (https://developers.google.com/gdata/docs/resumable_upload) but never send the actual content.

Resumable upload is not needed when creating an empty file, instead send your request to https://docs.google.com/feeds/default/private/full

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.