Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Doc Api : download inline object

I'm creating a Google Doc to HTML converter, I want to use the Doc Api and not export it as HTML using the Drive Api :

$service = new Google_Service_Docs($client);
$request = $service->documents->get($docId);

$elements = $request->getBody()->getContent();

$elements is an array of Google_Service_Docs_StructuralElement

Looping through paragraph > elements, if there is an inline object, the inlineObjectElement property is set with a Google_Service_Docs_InlineObjectElement

Question is : how to get the content of an Google_Service_Docs_InlineObjectElement to save it as a file ? All we have in this object is an inlineObjectId...

like image 418
Jérome B Avatar asked Feb 13 '19 22:02

Jérome B


People also ask

What is inline in Google Docs?

This update gives you the option to choose to create a new Google Doc, Google Sheets, or Google Slides or attach an existing document to your project. Once your document is attached, you can draft, edit, and comment on your content right inside your project by choosing “Edit Inline.”

Can you download from Google Drive with view only?

Yes it can be set up that way as long as you do not choose the option to "Disable" downloads.


1 Answers

I was able to find a solution for this on this blog post.

Basically, all inline elements are located at:

$inlineObjects = $request->getInlineObjects();

Btw. I recommend renaming "$request" to "$document"

Now, with the inlineObjectId you can get the particular object you want - and there, you get a contentUri which contains the binary content.

Here, a screenshot of $inlineObjects contents, which is an assoc array. The key is the inlineObjectId:

Screenshot of the Google_Service_Docs_InlineObject in var dumper

like image 195
Armin Avatar answered Sep 28 '22 06:09

Armin