本文介绍了Google Picker API无效的原始值错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,Google Picker停止了对我的Google表格加载项的使用,但未更改任何代码.模态对话框中的错误显示为:

Today Google Picker stopped working in my Google Sheets add-on without any changes to the code. The error in the modal dialogue reads:

控制台中的错误是:

删除postMessage ..是从意外的窗口

dropping postMessage.. was from unexpected window

删除postMessage ..是从意外的窗口

dropping postMessage.. was from unexpected window

加载'https://docs.google.com/picker?protocol=gadgets&origin=https%3A%2F%2Fdocs.google.com%2F&sdr=时遇到无效的'X-Frame-Options'标头true& title& oauth_token =< oathToken>& developerKey =< developerKey>& hostId = n-a6p4dq *** d6wq-0lu-script.googleusercontent.com& relayUrl = https%3A%2F%2Fn-a6p4dq *** d6wq-0lu-script.googleusercontent.com%2Ffavicon.ico& nav =((%22documents%22%2Cnull%2C%7B%22selectFolder%22%3Atrue%2C%22parent%22%3%3A%22root%22%7%D)%2C(%22documents%22%2Cnull%2C%7B%22dr%22%3Atrue%2C%22includeFolders%22%3Atrue%7D))& rpcService = qhurmoc5w4l7& rpctoken = xssf8gcggcg2x8& thirdParty = true#rp:'ALLOW-FROM https://docs.google.com/'不是公认的指令.标头将被忽略.

Invalid 'X-Frame-Options' header encountered when loading 'https://docs.google.com/picker?protocol=gadgets&origin=https%3A%2F%2Fdocs.google.com%2F&sdr=true&title&oauth_token=<oathToken>&developerKey=<developerKey>&hostId=n-a6p4dq***d6wq-0lu-script.googleusercontent.com&relayUrl=https%3A%2F%2Fn-a6p4dq***d6wq-0lu-script.googleusercontent.com%2Ffavicon.ico&nav=((%22documents%22%2Cnull%2C%7B%22selectFolder%22%3Atrue%2C%22parent%22%3A%22root%22%7D)%2C(%22documents%22%2Cnull%2C%7B%22dr%22%3Atrue%2C%22includeFolders%22%3Atrue%7D))&rpcService=qhurmoc5w4l7&rpctoken=xssf8g42xc2&thirdParty=true#rpctoken=xssf8g42xc2': 'ALLOW-FROM https://docs.google.com/' is not a recognized directive. The header will be ignored.

错误可能与我执行 setOrigin()的这一行代码有关:

It maybe that the error is linked to this line of code where I do setOrigin():

        var picker = new google.picker.PickerBuilder()
            .addView(driveView)
            .addView(drivesView)
            .hideTitleBar()
            .setOAuthToken(token)
            .setDeveloperKey(DEVELOPER_KEY)
            .setCallback(pickerCallback)
        --> .setOrigin(google.script.host.origin)
            .setSize(DIALOG_DIMENSIONS.width - 2,
                DIALOG_DIMENSIONS.height - 2)
            .build();

但是此行直接来自Google Picker API的文档,并且之前可以正常工作.如果我更改 google.script.host.origin ,则会将 https://docs.google.com 作为url返回到 https://n-a6p4dqsl *** 6wcd6wq-0lu-script.googleusercontent.com ,我得到了相同的错误和一个新错误,不是吗.

But this line is directly from the documentation of the Google Picker API and worked properly before. If I change google.script.host.origin, that returns https://docs.google.com as url to https://n-a6p4dqsl***6wcd6wq-0lu-script.googleusercontent.com, I get the same error and a new one, so that is not it.

我也无法将此添加为GCP项目中的授权javascript来源,因为它返回以下错误:

I also cannot add this as as an authorized javascript origin in the GCP project as it returns the following error:

((已经有一段时间了)

这似乎是一个新错误,我无法在Google的问题跟踪器或StackOverflow上都找不到答案.

This seems like a new error and I wasn't able to find an answer neither on Google's issues tracker nor on StackOverflow.

任何人也面临着这个问题,或者知道如何处理吗?

Anyone facing this as well or have an idea how it can be handled?

推荐答案

添加一个结束符,解决此问题的唯一方法是删除后面的斜杠

Putting an end, the only way to solve this is to remove the trailing slash after

来自

docs.google.com/

docs.google.com/

收件人

docs.google.com

docs.google.com

相反,

google.script.host.orgin给出了"https://docs.google.com/"导致错误.因此,您需要将代码硬编码为

The google.script.host.orgin gives the "https://docs.google.com/" which causes the error. Hence you need to hard code as

" https://docs.google.com"

"https://docs.google.com"

Google最近进行了一些更改,可能使此问题冒泡了.

Google has made some changes recently which might have bubbled this issue.

更新

您可以使用此功能-并调用- ...... setOrigin(getOrigin())

You can use this function - and call - ...... setOrigin(getOrigin())

function getOrigin() {
    var url = google.script.host.origin;
    return url.substr(url.length - 1) === "/" ? url.substr(0, url.length - 1) : url;
}

这篇关于Google Picker API无效的原始值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:13