我如何获得“可共享ID"?使用Google脚本中的DriveApp将图片插入Google表格单元中的图片? [英] How can I get a "shareable ID" of a picture using the DriveApp in Google script to insert it in a Google sheet cell?

查看:122
本文介绍了我如何获得“可共享ID"?使用Google脚本中的DriveApp将图片插入Google表格单元中的图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在电子表格的单元格中插入位于云端硬盘上的图片.为此,我需要图片文件的可共享ID.可以通过手动单击文件并单击获取共享链接"来获取共享ID.

I would like to insert a picture located on my Drive in a cell on a spreadsheet. To do so, I need the shareable ID of the picture file. The shareable ID can be obtained by manually clicking on the file and click "Get shareable link".

这是示例图片的链接: https://drive.google.com/打开?id = 1qoWmf1eks6BZiMNv1PByvr6lcPLT0png

This is the link to the example image: https://drive.google.com/open?id=1qoWmf1eks6BZiMNv1PByvr6lcPLT0png

ID为:1qoWmf1eks6BZiMNv1PByvr6lcPLT0png

with the ID being : 1qoWmf1eks6BZiMNv1PByvr6lcPLT0png

当我尝试执行我的Google脚本并使用file.getId()时,我获得了另一个ID.使用通过我的脚本获得的ID时,该图像未显示在Google表格单元格中.图像仅与手动获取的可共享链接中的ID一起显示.有人知道如何解决这个问题吗?

When I try to execute my google script and use file.getId(), I obtain another ID. The image does not appear in the google sheet cell when using that the ID obtained with my script. The image appear only with the ID from the shareable link obtained manually. Does someone know how to solve this?

谢谢

请参见下面的脚本以获取文件ID:

See the script to obtain the file ID below:

function getFileID() {
  var name = "m285741_200316_001_FOV_enhanced.png";
  var files = DriveApp.getFilesByName(name);

  while (files.hasNext()) {

    var file = files.next();
   file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
   var URL = file.getUrl();
   var ID = file.getId();
    
 }
  return ID;
 
}

推荐答案

不幸的是,无法运行需要特殊授权的自定义函数.

Unfortunately it's not possible to run custom functions that require special authorization.

您可以在文档中阅读:

如果您的自定义函数抛出错误消息您没有调用X服务的权限.",则该服务需要用户授权,因此无法在自定义函数中使用.

If your custom function throws the error message You do not have permission to call X service., the service requires user authorization and thus cannot be used in a custom function.

要使用除上面列出的服务以外的其他服务,请创建一个运行Apps脚本功能的自定义菜单,而不是编写一个自定义功能.通过菜单触发的功能将在必要时询问用户授权,因此可以使用所有Apps Script服务.

To use a service other than those listed above, create a custom menu that runs an Apps Script function instead of writing a custom function. A function that is triggered from a menu will ask the user for authorization if necessary and can consequently use all Apps Script services.

考虑使用建议的解决方法. 此处有关使用自定义菜单的指南.

Consider using the suggested workaround. Here a guide on using custom menus.

这篇关于我如何获得“可共享ID"?使用Google脚本中的DriveApp将图片插入Google表格单元中的图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆