微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Google 驱动器文件选择器:点击“选择”时对话框不会关闭

如何解决Google 驱动器文件选择器:点击“选择”时对话框不会关闭

我知道这已经被问过很多次了,我浏览了无数关于这个问题的线程,但似乎没有解决方案适用于我的情况。使用谷歌驱动器文件选择器,在选择过程中,我始终在控制台中收到此错误

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

尽管出现错误,选择器第一次工作正常,但如果我第二次打开它,选择一个文件并单击“选择”按钮不会关闭对话框。在选择的文件返回到回调后,要关闭对话框,用户必须点击右上角的“取消”或“x”按钮。我不确定控制台错误和选择器对话框问题是否相关。

我已阅读所有这些内容

我是谷歌谷歌驱动器文件选择器和谷歌驱动器 API,这是源代码,它几乎“按原样”取自谷歌驱动器选择器文档中的在线示例:

 <script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
 <script>
        // The browser API key obtained from the Google Api Console.
        // Replace with your own browser API key,or your own key.
        var developerKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

        // The Client ID obtained from the Google Api Console. Replace with your own Client ID.
        var clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

        // Replace with your own project number from console.developers.google.com.
        // See "Project number" under "IAM & Admin" > "Settings"
        var appId = "xxxxxxxxxxxxxxxx";

        // Scope to use to access user's Drive items.
        var scope = ['https://www.googleapis.com/auth/drive.file'];

        var pickerApiLoaded = false;
        var oauthToken;

        // Use the Google Api Loader script to load the google.picker script.
        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();
            }
        }

        // Create and render a Picker object for searching images.
        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);
            }
        }

        // A simple callback implementation.
        function pickerCallback(data) {
            if (data.action == google.picker.Action.PICKED) {
                var fileId = data.docs[0].id;
                alert('The user selected: ' + fileId);
            }
        }
  </script>
  <div>
        <button type="button" onclick="loadPicker()">Load google drive picker</button>
  </div>
  • 授权的 javascript 源和重定向 uri 包含在 google 控制台中,所有 uri 都在 SSL 下。

  • 我已启用选择器和谷歌驱动器 API

  • 我试图在没有效果的情况下注释掉 setDeveloperKey() 和 setAPPid()

  • 范围包含在开发者控制台 oauth 同意屏幕部分

  • 我没有收到上述许多问题中常见的 cors 错误或“无效的 x-frame-options 标头”

  • 我尝试在加载 API 时包含 API 密钥作为参数,例如:

    src="https://apis.google.com/js/api.js?key=xxxxxxxxxxxxxxxxxxx"

  • 源由本地 html 服务器 (IIS) 提供服务,我的生产服务器上也有同样的问题。两者都在 SSL 下。

  • 我已经按照文档中的建议尝试了 picker.setorigin(window.location.protocol + '//' + window.location.host )

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?