我创建了一个插件,我在/login.jsp和/secure/Dashboard.jspa的登录小工具上有一个google登录按钮。
一切都在/login.jsp上运行良好,但Google API未在/dashboard.jspa上加载。在我的.js中: -
AJS.$(function() {
var po = document.createElement("script");
po.type = "text/javascript";
po.async = true;
po.src = "https://apis.google.com/js/client:platform.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(po, s);
});
gapi.auth.signIn({
callback: gPSignInCallback,
clientid: CLIENT_ID,
cookiepolicy: "single_host_origin",
approvalprompt: "force",
requestvisibleactions: "http://schema.org/AddAction",
scope: "https://www.googleapis.com/auth/plus.login email"
})
在/dashboard.jspa页面上,gapi.auth未定义正在抛出控制台。
您需要首先定义'auth'对象并使用gapi.auth2.init()调用对其进行初始化。
以下是定义auth2对象的示例:
var auth2="";
var onGoogleLoad = function () {
gapi.load('auth2', function () {
auth2 = gapi.auth2.init({
client_id: 'YOUR CLIENT ID',
})
enableGoogleButton()
})
}