4

So, the problem is that popup blocking the window open even if it is done by a user action, click for example..

gapi.auth.authorize({
   client_id: this.client_id,
   scope: this.scopes,
   access_type: 'online',
   immediate: immediate
}, function(authResult) {
   console.log(authResult)
});

If i simply open the window on user click as here:

$('.some').click(funciton(){
    window.open(someurl)
})

it works fine, but if i did it throw the gdrive api(gapi.auth.authorize), this blocking anyway.

A must, I can not force users to off popap blocking. I hope that anybody now how solved it :), thanks

4

5 回答 5

5

尝试这个:

在对 client.js 的调用中包含一个 onload 事件

<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>

从 onload 函数调用 gapi.auth.init :

function handleClientLoad() { window.setTimeout(gapi.auth.init,1); }

在您的授权配置中设置立即:false。

检查页面流程中的 1. 是否低于 2.。

于 2013-05-07T08:52:48.053 回答
4

只需添加参考 https://developers.google.com/api-client-library/javascript/reference/referencedocs

gapi.auth.init(callback) 初始化授权功能。在客户端加载时调用它,以防止弹出窗口阻止程序阻止 gapi.auth.authorize 调用上的身份验证窗口。

ps:投票需要15个声望..所以不能投票给本的答案:)

于 2013-10-08T05:18:53.477 回答
3

不是来自用户事件的弹出窗口将被阻止,具体取决于您的浏览器设置。您可以尝试将immediate设置为 false:

gapi.auth.authorize({
   client_id: this.client_id,
   scope: this.scopes,
   immediate: false
}, function(authResult) {
   console.log(authResult)
});

在您已经授权应用程序后,您可以使用此代码刷新访问令牌。

于 2013-03-28T14:17:32.447 回答
0

第一次调用 gapi.auth.authorize 可以触发弹出窗口阻止程序。防止这种情况的最佳方法是设置一个用户触发的操作,该操作使用 immediate: false 参数调用 gapi.auth.authorize。

引用自 api 文档:https ://developers.google.com/api-client-library/javascript/features/authentication#popup

于 2016-01-20T14:59:59.737 回答
0

您只需要gapi.auth2.getAuthInstance().isSignedIn.get();无按钮授权许可。这会禁用弹出窗口。

gapi.client.init({
     discoveryDocs: DISCOVERY_DOCS,
     clientId: CLIENT_ID,
     scope: SCOPES
}).then(function () {    
     // Handle the initial sign-in state.
     gapi.auth2.getAuthInstance().isSignedIn.get();
});
于 2017-11-02T17:32:56.810 回答