Reputation: 55
I'm wondering if it's possible to obtain the URI for an image located on one's Google Drive.
Drive API: GET https://www.googleapis.com/drive/v2/files/{fileId}
(Using the Google Docs batchUpdate ReplaceImageRequest to replace images)
uri = file["selfLink"]
=> "Invalid requests[0].replaceImage: Access to the provided image was forbidden."
uri = file["webContentLink"]
=> "Invalid requests[0].replaceImage: There was a problem retrieving the image. The provided image should be publicly accessible, within size limit, and in supported formats."
uri = file["alternateLink"]
=> (see above)
uri = file["embedLink"]
=> (see file["webContentLink"]
)
I was trying these properties– expecting the Docs API to automatically interpret drive links. But this was probably just wishful thinking; as it of course, did not work.
Upvotes: 3
Views: 2536
Reputation: 201428
I believe your goal as follows.
When the image is put to the Google Document using Docs API, it seems that the URL of the image is the external URL. So in your case, you can use the URL of webContentLink
. But the file is required to be publicly shared as the viewer with "Anyone with the link". I think that the reason for your issue is this. So please do the following flow.
webContentLink
of the shared image.Upvotes: 3