Google Sheets Image() 函数现在要求用户点击“允许访问”

问题描述 投票:0回答:1

对于任何电子表格,新近默认阻止从外部方访问数据。此更改于 2024 年 7 月 2 日开始发生。我有许多 PHP 脚本,可以创建电子表格并以 PDF 形式以编程方式打印它们,但现在电子表格无法再访问来自外部各方的数据,因此结果是错误的。

我在 Google Sheets API 文档中找不到如何允许以编程方式访问的方法。

在第 7 天之前,所有流程都正常工作,图像 URL 是公开的,没有访问限制,任何人都有以编程方式授予访问权限的解决方案吗?

这是我使用 IMAGE() 函数的一些代码:

foreach($ORDEN["pics_docs"] as $pic)
{
    $currentRow++;
    array_push($requests_mergeCellsInRow, get_mergeCellsInRow_request($currentRow, $sc, $ct, $sheetId));
    array_push($requests_formatForCells, get_formatConceptWForRow($currentRow, $sc, $ct, $sheetId));
    array_push($requests_updateDimensionPropertiesForRow, get_updateDimensionPropertiesForRow_request($currentRow, $imgw, $sheetId));
    array_push($values_forCells_userEntered,["=IMAGE(\"".$urlImages."/".$id_orden."/".$pic["doc_name"]."\"; 1)", "", "", "", "", "", "", "", "", ""]);
    $currentRow++;
    array_push($values_forCells_userEntered, []);
}
insertValuesOnCellsRange($values_forCells_userEntered, $sheetName.'!A3', $serviceSheets, $spreadsheetID, "USER_ENTERED");
batchUpdate(array_merge($requests_mergeCellsInRow, $requests_bordersForCells, $requests_formatForCells, $requests_updateDimensionPropertiesForRow), $serviceSheets, $spreadsheetID);

除了锁定权限会破坏流程外,该工作表是正确的,我分配给该工作表的唯一权限是:

    $newPermission = new Google_Service_Drive_Permission();
    $newPermission->setType("anyone");
    $newPermission->setRole("reader");
    $result = $serviceDrive->permissions->create($spreadsheetID, $newPermission, array('fields' => 'id'));

我附上了几张带有问题图例的图像

google-sheets google-api
1个回答
0
投票

我最近遇到了同样的问题,我将这个应用程序脚本函数放在一起来修复它:

function addExternalPartyPermission(ss_caller) {
  ss_callerId = ss_caller.getId();
  const token = ScriptApp.getOAuthToken();
  // adding permission by fetching this url
  const url = `https://docs.google.com/spreadsheets/d/${ss_callerId}/externaldata/allowexternalurlaccess?token=${token}&includes_info_params=true&cros_files=false`;

  const params = {
    method: 'post',
    headers: {
      Authorization: 'Bearer ' + token,
    },
    muteHttpExceptions: true
  };

  UrlFetchApp.fetch(url, params);
}

将其作为电子表格所有者帐户运行,并传入您要为其添加权限的电子表格作为“ss_caller”,然后将添加权限。

© www.soinside.com 2019 - 2024. All rights reserved.