Google Docs API Download file using curl

Does anyone know how to publish a file using curl in google docs. I am writing this code:

$header[] = "Authorization: GoogleLogin auth=seretkey"; $header[] = "Content-Type: application/pdf"; $header[] = "Slug: testdoc"; $header[] = "Content-Length: ".$_FILES['file']['size'].""; $url = "http://docs.google.com/feeds/documents/private/full"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name'])); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $response = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); 

And it works fine only if I use plain / text Content-type with text files, but if my downloaded file is in binary mode, I got an error code 417 http, for example, with pdf documents.

I am trying to change this line

 curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name'])); 

For this

 curl_setopt($ch, CURLOPT_POSTFIELDS, array("file"=>"@".$_FILES['file']['tmp_name'])); 

But I have 417 response error code again. Only with plain / text answer - 201.

An example of downloadable Google document headers from an official source

 POST /feeds/documents/private/full HTTP/1.1 Host: docs.google.com Authorization: <your authorization header here> Content-Length: 81047 Content-Type: application/vnd.ms-excel Slug: Example Spreadsheet ... spreadsheet contents here ... 
+4
source share
1 answer

Check this article . This gives an excellent record on how to use CURL, including how to publish variables. I'm not sure how to use this with google docs, but while you follow their instructions, this should help you sort out the post var problem.

+1
source

Source: https://habr.com/ru/post/1301367/


All Articles