谷歌授权oAuth 2.0没有弹出和同意

时间:2017-02-16 00:00:10

标签: javascript authentication google-api oauth-2.0 authorization

我需要在确认弹出谷歌窗口后获取JSON中的auth代码而不是url。我试着像谷歌文档https://developers.google.com/identity/sign-in/web/server-side-flow

那样做

但这不起作用!我做错了什么?这是我的代码。    

<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer></script>
<script>
    function start() {
        gapi.load('auth2', function() {
            auth2 = gapi.auth2.init({
                client_id: '0101010101-p5a3fgbkeso3loqg157001l4deajshot.apps.googleusercontent.com',
                scope:'https://www.googleapis.com/auth/drive'
                    // Scopes to request in addition to 'profile' and 'email'
                    //scope: 'additional_scope'
            });
        });

    }
</script>
</head>
<body>
<button id="signinButton">Sign in with Google</button>
<script>
    $('#signinButton').click(function() {
    // signInCallback defined in step 6.
    auth2.grantOfflineAccess({'redirect_uri': 'postmessage'}).then(function(resp) {
        var auth_code = resp.code;

    });
});

0 个答案:

没有答案