如何获取URL到Google文档图像 [英] How to get the url to Google doc image
问题描述
我有一个Google文档文档,其中包含一张图片.我发现图像的objectId
如此处 https://developers.google所述.com/docs/api/reference/rest/v1/InlineObject ,但我不明白如何获取该图片的网址.
我尝试在云端硬盘中搜索此objectId
,但它返回找不到文件.
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.
有什么想法吗?
更新
如@Tanaike所述,图像信息包含在result.inlineObjects
和
而不是直接在段落中.
As noted by @Tanaike the image info is contained in the result.inlineObjects
and
not directly in the paragraph.
推荐答案
- 您要使用Google Docs API检索Google文档中插入的图像的URL.
如果我的理解正确,那么这个答案如何?
If my understanding is correct, how about this answer?
我认为您正在检查的inlineObjectElement
的属性在该段落中.插入的图像的信息可以在inlineObjects
的属性中看到. URL可以在ImageProperties
的属性中看到.
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
.
端点如下.
GET https://docs.googleapis.com/v1/documents/{documentId}?fields=inlineObjects
- 在这里,作为示例,将
inlineObjects
用作fields
.您还可以将*
用作fields
. - Here, as a sample,
inlineObjects
is used asfields
. You can also use*
asfields
.
可以按以下方式检索URL.假定response
是端点上方的返回值.
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.###
是您的问题中的inlineObjectId
. - 如果从外部的URL插入图像,则该URL与插入图像时使用的URL相同.
- 如果图像是从Google云端硬盘插入的,则网址如下所示.
-
https://lh3.google.com/u/0/d/{fileId}=w###-h###
- 在这种情况下,
{fileId}
是图像的文件ID.您可以使用此文件ID检索原始文件. kix.###
isinlineObjectId
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. - Method: documents.get
- InlineObject
- ImageProperties
如果我误解了您的问题,而这不是您想要的结果,我深表歉意.
If I misunderstood your question and this was not the result you want, I apologize.
这篇关于如何获取URL到Google文档图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-