如何在replaceImage Google文档请求中使用Google云端硬盘存储的JPEG图像?

问题描述

我正在通过Google docs API构建google文档。 我的文档是通过模板创建的:将模板复制到新位置,替换文本和替换图片

一切正常,直到尝试替换图像为止。

要放入文件中的图像存储在Google云端硬盘文件夹中。

因此,我有2个问题: 第一个是如何将replaceImage请求与我的图像的查看URL一起使用? 通过使用以下代码,我面临400错误

IDictionary<string,InlineObject> inlineObjects = doc.InlineObjects;
//Get the objet ID
string imageObjectId = inlineObjects.First().Value.ObjectId;

BatchUpdateDocumentRequest batchUpdateRequest = new BatchUpdateDocumentRequest {
   Requests = new List<Google.Apis.Docs.v1.Data.Request>()
};
var request = new Google.Apis.Docs.v1.Data.Request {
ReplaceImage = new ReplaceImageRequest() {
    ImageObjectId = imageObjectId,Uri = "https://docs.google.com/uc?export=view&id=1pmXP9TFolKMQoUlXHllvIrQPlZiDxId6"
}};
            
batchUpdateRequest.Requests.Add(request);
DocumentsResource.BatchUpdateRequest updateRequest = 
_docSercive.Documents.BatchUpdate(batchUpdateRequest,fileId);
            
BatchUpdateDocumentResponse updateResponse = updateRequest.Execute();

错误

Invalid requests[0].replaceImage: Access to the provided image was forbidden. [400]
Errors [
    Message[Invalid requests[0].replaceImage: Access to the provided image was forbidden.] Location[ - ] Reason[badRequest] Domain[global]
]'

第二个是如何通过从Google Drive API检索图像URL来使其工业化? 当我尝试立即获取它时,我只能访问图像名称和扩展名:

Google.Apis.Drive.v3.Data.File f = _service.Files.Get(fileId).Execute();

我应该为这个file.get调用使用查询参数吗?

感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)