2
votes

I have a Google Docs document which contains one image. I found images's objectId as stated here https://developers.google.com/docs/api/reference/rest/v1/InlineObject but I can't understand how to get an url to that image. I tried searching for this objectId in Drive but it returns File not found.

Any ideas ?

do

Update

As noted by @Tanaike the image info is contained in the result.inlineObjects and not directly in the paragraph.

enter image description here

2

2 Answers

3
votes
  • You want to retrieve the URL of the inserted image in Google Document using Google Docs API.

If my understanding is correct, how about this answer?

I think that the property of inlineObjectElement that you are checking is in the paragraph. The information of the inserted images can be seen at the property of inlineObjects. And the URL can be seen at the property of ImageProperties.

The endpoint is as follows.

Endpoint:

GET https://docs.googleapis.com/v1/documents/{documentId}?fields=inlineObjects
  • Here, as a sample, inlineObjects is used as fields. You can also use * as fields.

Result:

The URL can be retrieved as follows. It supposes that response is the returned value from above endpoint.

url = response.inlineObjects["kix.###"].inlineObjectProperties.embeddedObject.imageProperties.sourceUri
  • kix.### is inlineObjectId in your question.
  • If the image is inserted from the URL of outside, the URL is the same with the URL which was used when the image was inserted.
  • If the image is inserted from Google Drive, the URL is like below.
    • https://lh3.google.com/u/0/d/{fileId}=w###-h###
    • In this case, {fileId} is the file ID of the image. You can retrieve the original file using this file ID.

References:

If I misunderstood your question and this was not the result you want, I apologize.

3
votes

Step #1: Right-click and Copy the image from the Google Doc.
Step #2: Paste into dynalist.io.

(Note: Dynalist doesn't allow you to paste images, but you can paste images from Google Docs because it just adds the link.)

I understand that this may not help if you are trying to do something with the API, but for finding the link to a single image, it is the simplest method I've found.