使用gapi.auth2.init
但我们从未达到回调方法onSuccess
。
这基本上取自:https://developers.google.com/identity/sign-in/web/session-state
控制台中显示的错误是:
QuotaExceededError:DOM异常22:尝试添加 存储超出配额的东西。
以下代码:
<html>
<head>
<script src="https://apis.google.com/js/api:client.js"></script>
<script type="text/javascript">
var auth2;
var initClient = function() {
gapi.load('auth2', function(){
auth2 = gapi.auth2.init({
client_id: 'XXXXXXXXX.apps.googleusercontent.com',
scope : 'https://www.googleapis.com/auth/plus.login'
});
auth2.attachClickHandler('customBtn', {}, onSuccess, onFailure);
});
};
var onSuccess = function(user) {
console.log('Signed in as ' + user.getBasicProfile().getName());
};
var onFailure = function(error) {
console.log(error);
};
function startApp() {
initClient();
}
<body>
<div id="customBtn" class="customGPlusSignIn" />
<p>Demo</p>
</body>
</html>
<script>startApp();</script>