Upload an xls file to google docs with cURL call only(no Gdata API)

Discussion in 'Google API' started by AvishekKumar, Feb 9, 2012.

  1. #1
    Hi,

    Is there any way to upload an xls file to google docs using only cURL call through php.
    I have tried with Gdata but unfortunately that didn't worked
    (giving me an error uploaded file cannot be imported)

    here is the code with with I am trying with but its giving me an error 411, that's an error Post Request requires a header Content-length
    though I have set the Content-Length Header

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


    $headers=array(
    "Authorization:GoogleLogin auth=". $auth,
    "Content-Type: application/atom+xml",
    "Content-Length:". strlen($xml),
    "Slug:test"
    );
    // Make the request
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://docs.google.com/feeds/documents/private/full");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER , 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    $response = curl_exec($ch);

    thanks
    -avisheks
     
    AvishekKumar, Feb 9, 2012 IP
  2. AvishekKumar

    AvishekKumar Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi all,
    can one help me out of this I am still with no conclusion
    :(
    thanks and regards
    -avisheks
     
    AvishekKumar, Feb 20, 2012 IP