如何防止谷歌API驱动器选择器的弹出窗口拦截器

时间:2014-12-26 19:37:55

标签: javascript

我的html表单上有google驱动器选择器。但是,当我单击按钮时,我收到“弹出窗口被阻止”的浏览器消息。

我需要这项工作而无需用户允许。你能不能看看我的代码让我知道如何更改它以便在没有用户启用弹出窗口的情况下工作

由于

这是代码..


 <a id="auth-button" class="google-drive-btn"  ng-model="resume" href="#" ng-   click="onGoogleLoad()">Choose from Google Drive</a>

$scope.onGoogleLoad = function () {
    var flag = false;
    $http.post('/api/controllers/googledownload/getClientkey').
    success(function (data, status, header, config) {
        gapi.client.load('drive', 'v2', null);
        gapi.load('auth', { 'callback': onAuthApiLoad });
        gapi.load('picker','1');

        function onAuthApiLoad() {

            window.gapi.auth.authorize({
                'client_id': data.clientID,
                'immediate': flag,
                'scope': ['https://www.googleapis.com/auth/drive']
            }, handleAuthResult);
        }

        function handleAuthResult(authResult) {

            if (authResult && !authResult.error) {

                oauthToken = authResult.access_token;
                createPicker();
            }
            else
            {

                flag = true;
                onAuthApiLoad();

            }
        }


        function createPicker() {
            var picker = new google.picker.PickerBuilder()
                .addView(new google.picker.DocsView())
                .setOAuthToken(oauthToken)
                .setCallback(pickerCallback)
                .build();
            picker.setVisible(true);
        }

        function pickerCallback(data) {
            if (data.action == google.picker.Action.PICKED) {
                $scope.showspinner = true;
                var doc = data.docs[0];
                var fileId = doc.id;
                var request = gapi.client.drive.files.get({
                    'fileId': fileId
                });
                request.execute(function (resp) {
                    var token = gapi.auth.getToken();

                    var fileData = {
                        name: resp.title,
                        link: resp.downloadUrl,
                        accessToken: token.access_token,
                        tokenType: token.token_type,
                        mimeType: resp.mimeType
                    };
                    var jsondata = JSON.stringify({ FileData: fileData });

                    $http.post('/api/controllers/files/CloudDownload', { googleFileData: fileData}).
                    success(function (data, status, headers, config) {
                        onFileUploadSuccess(data);
                    }).
                    error(function (data, status, header, config) {

                        $scope.showspinner = false;

                    });
                });
            }
            else if (data.action == google.picker.Action.CANCEL) {

                $scope.showspinner = false;

            }

        }

    }).
    error(function (data, status, header, config) {
        $scope.showspinner = false;


    });

}

0 个答案:

没有答案