Google Dokümanlar Klasör post CSV

0 Cevap php

Aslında bir. CSV bir sorgunun sonuçlarını dökümü ve sonra bizim kurumsal Google Dokümanlar üzerinde belirli bir klasöre yüklemek için bir PHP komut dosyası üzerinde çalışıyor.

Dosyası oluşturulur ve sadece iyi Docs üzerinden gönderilir. Ancak, doğru dizinde konuyor değildir.

Bu ben kullanıyorum işlevi olduğu $file, $folder, ve $newtoken [(4)] {'dump.csv' gibi dizeleri }, [auth token from Google].

function insert($file, $folder, $newtoken){
    $mime = "Media multipart posting\n--END_OF_PART\n";
    $mime .= "Content-Type: application/atom+xml\n\n";
    $xml="<?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#document\"/>
        <title>example document</title>
        <docs:writersCanInvite value=\"true\" />
    </entry>
    ";
    $mime.=$xml."\n--END_OF_PART\n";

    $document = "Content-Type: text/plain\n\n";
    $handle = fopen($file, "r");
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    $document.=$contents;
    $itemURL = "https://docs.google.com/feeds/default/private/full";
    $mime .= $document."\n--END_OF_PART--\n";

    $headers = array();
    $headers[] = "POST /feeds/default/private/full/folder%3A".$folder."/contents HTTP/1.1";
    $headers[] = "Host: docs.google.com";
    $headers[] = "GData-Version: 3.0";
    $headers[] = "Authorization: GoogleLogin auth=".$newtoken."";
    $headers[] = "Content-Length: ".strlen($mime);
    $headers[] = "Content-Type: multipart/related; boundary=END_OF_PART";
    $headers[] = "Slug: Test";

    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$itemURL);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl,CURLOPT_POSTFIELDS, $mime);
    $result = curl_exec($curl);
    curl_close($curl);

    echo 'Response: '.$result;
}

Maybe I have the folder ID wrong (just copied from URL while viewing in Google Docs)?
Bonus: Can I manipulate the content-type headers to get Google to convert the file to a spreadsheet?

0 Cevap