无法在 'DOMWindow' 上执行 'postMessage':提供的目标来源 ('https://docs.google.com') 与收件人 window 的来源不匹配

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://docs.google.com') does not match the recipient window's origin

我正在尝试允许用户通过 google 选择器从他们的 google 驱动器中 select 文件。我关注了[官方][1]docs/example。但是在浏览器控制台中出现以下错误:

我在 google 开发者控制台上进行了以下设置:

我也试过部署我的应用程序,但仍然遇到同样的错误。

这是我使用的代码:

var developerKey = 'xxxxxxxYYYYYYYY-12345678';

var clientId = "1234567890-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com"

var appId = "1234567890";

var scope = ['https://www.googleapis.com/auth/drive.file'];

var pickerApiLoaded = false;
var oauthToken;

function loadPicker() {
  gapi.load('auth', {'callback': onAuthApiLoad});
  gapi.load('picker', {'callback': onPickerApiLoad});
}

function onAuthApiLoad() {
  window.gapi.auth.authorize(
      {
        'client_id': clientId,
        'scope': scope,
        'immediate': false
      },
      handleAuthResult);
}

function onPickerApiLoad() {
  pickerApiLoaded = true;
  createPicker();
}

function handleAuthResult(authResult) {
  if (authResult && !authResult.error) {
    oauthToken = authResult.access_token;
    createPicker();
  }
}

function createPicker() {
  if (pickerApiLoaded && oauthToken) {
    var view = new google.picker.View(google.picker.ViewId.DOCS);
    view.setMimeTypes("image/png,image/jpeg,image/jpg");
    var picker = new google.picker.PickerBuilder()
        .enableFeature(google.picker.Feature.NAV_HIDDEN)
        .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
        .setAppId(appId)
        .setOAuthToken(oauthToken)
        .addView(view)
        .addView(new google.picker.DocsUploadView())
        .setDeveloperKey(developerKey)
        .setCallback(pickerCallback)
        .build();
     picker.setVisible(true);
  }
}

function pickerCallback(data) {
  if (data.action == google.picker.Action.PICKED) {
    var fileId = data.docs[0].id;
    alert('The user selected: ' + fileId);
  }
}

我是不是做错了什么? [1]: https://developers.google.com/picker/docs

这是一个已报告的错误

https://issuetracker.google.com/177046274

我会去给这些问题加注星标,让 Google 知道它们对您有影响。

我可以重现它,选择器可以工作,但是出现这个错误:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://docs.google.com') does not match the recipient window's origin ('http://localhost:8000').

另一个相关错误

相关说明,如果您想让缩略图出现在选择器中,您需要使用更广泛的 drive.readonlydrive 范围:

https://issuetracker.google.com/64622983