Google Docs API

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
I'm tring to upload a files to the google docs service using the api but have hit a dead end. The script below will move a plain text file but not a pdf.. according to the documentation they say it can be done but I'm going cross eyed reading it over and over again.

Been tinkering with it but keep coming back to an "DataServiceForbiddenExceptionFiles must be uploaded using the resumable upload mechanism." error. Think it's to do with the headers but can't quite figure out what.

PHP:
            $headers = array(
                "Authorization: GoogleLogin auth=" . $this->auth,
                "GData-Version: 3.0",
                "Content-Length: ". filesize($file),
                "Content-Type: ". $this->returnMIMEType($file),
                "Slug: ". $name);
        
        
            if($idFolder)
            {
                $url = "https://docs.google.com/feeds/default/private/full/folder%3A". $idFolder ."/contents";
            }
            else
            {
                $url = "https://docs.google.com/feeds/default/private/full";
            }        
        
            // Make the request
            curl_setopt($this->curl, CURLOPT_URL, $url);
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($this->curl, CURLOPT_POST, true);
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, file_get_contents($file));
            curl_setopt($this->curl, CURLOPT_VERBOSE, true);
        
            // Execute
            $response = curl_exec($this->curl);
            print_r($response );
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Last edited:
Top