Google脚本将驱动器中的图像替换为AllShapesWithImage不再起作用 [英] Google script replaceAllShapesWithImage with image from drive doesn"t work any more

查看:78
本文介绍了Google脚本将驱动器中的图像替换为AllShapesWithImage不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从昨天开始,我的Google脚本之一不再起作用. 脚本

Since yesterday one of my google script doesn't work anymore. The script

  1. 在驱动器上拍摄图像
  2. 复制幻灯片
  3. 用图像替换形状

但是我得到了这个错误:

But I got this error:

提供的图像格式不受支持."

"The provided image is in an unsupported format."

->我拥有对图像的所有访问权限:它没有任何改变

-> I give all access to the image: it doesn't change anything

->如果我将URL放在驱动器之外,脚本将起作用

-> The script work if I take an url outside the drive

任何想法

function test_image(){
  var imageUrls = DriveApp.getFilesByName("DSC_3632.png");
  var file = "undefined";
  while ( imageUrls.hasNext()) {
    var file = imageUrls.next();
  }

  var imageUrl = file.getDownloadUrl() + "&access_token=" + ScriptApp.getOAuthToken();

  var model_file = DriveApp.getFileById("your-id");
  var presentation = model_file.makeCopy("totot");
  var presentation =Slides.Presentations.get(presentation.getId())

  var requests = [{
      "replaceAllShapesWithImage":
        {
          "imageUrl": imageUrl,
          "imageReplaceMethod": "CENTER_INSIDE",
          "containsText": {
            "text": "toto",
            "matchCase": false,
          }
        }
    }];


  var presentationId = presentation.presentationId

  var createSlideResponse = Slides.Presentations.batchUpdate({
    requests: requests
  }, presentationId);


}

推荐答案

这个答案怎么样?请认为这只是几个可能的答案之一.

How about this answer? Please think of this as just one of several possible answers.

我认为您出现问题的原因是由于对

I think that the reason of your issue is due to the following modification of official document.

首先,我们正在更改Google Drive API的授权.如果您使用查询参数中的访问令牌授权对Drive API的下载请求,则需要迁移请求以使用HTTP标头进行身份验证.从2020年1月1日开始,将不再支持对使用query参数中的访问令牌进行身份验证的files.get,revisions.get和files.export端点的下载调用,这意味着您需要更新身份验证方法./p>

First, we’re making changes to authorization for the Google Drive API. If you authorize download requests to the Drive API using the access token in a query parameter, you will need to migrate your requests to authenticate using an HTTP header instead. Starting January 1, 2020, download calls to files.get, revisions.get and files.export endpoints which authenticate using the access token in the query parameter will no longer be supported, which means you’ll need to update your authentication method.

在上述情况下,无法使用var imageUrl = file.getDownloadUrl() + "&access_token=" + ScriptApp.getOAuthToken();的URL.例如,当访问URL时,即使使用访问令牌,也会显示登录屏幕.

By above situation, the URL of var imageUrl = file.getDownloadUrl() + "&access_token=" + ScriptApp.getOAuthToken(); cannot be used. For example, when it accesses to the URL, the login screen is displayed even when the access token is used.

为了避免此问题,如何进行以下修改?

In order to avoid this issue, how about the following modification?

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