使用Oauth2 Google时的双重请求权限

时间:2019-05-16 10:33:35

标签: javascript google-oauth google-analytics-api google-signin google-api-js-client

使用“ client:auth2:analytics”(Google Authenticate&Analytics)时出现问题。选择帐户进行验证后,身份验证对话框中将出现另一个对话框,要求用户允许应用程序的某些许可(请参见下图),如何自动允许所有权限?

  • 请求用户确认权限。

enter image description here

  • 然后,仍然要求用户确认权限。

enter image description here

https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/analytics.manage.users
this.onLoad = function () {
  const thiss = this;
  window.onload = function () {
     gapi.load('client:auth2:analytics', function () {
      gapi.client.init({
       'apiKey': thiss.config.apiKey,
       'clientId': thiss.config.clientId,
       'scope': thiss.config.scope,
      }).then(function () {

       thiss.handleBtnAuthClickStateful('reset');

       thiss.GoogleAuth = gapi.auth2.getAuthInstance();

       thiss.onAuthClick();
      });
     });
  }
}
this.onAuthClick = function () {
   const thiss = this;
   $(document).on('click', `#${thiss.html.btnAuthAnalytics}`, function () {
     thiss.handleOnAuthClick();
   });
};
this.handleOnAuthClick = function () {
  const thiss = this;

  if (!thiss.handleValidate()) {
    thiss.handleResetAuth();

    thiss.GoogleAuth.signIn().then(function () {
      if (thiss.GoogleAuth.isSignedIn.get()) {
        thiss.handleAfterSignIn();
      }
    });
  }
};
this.handleResetAuth = function () {
  const thiss = this;

  thiss.GoogleAuth.signOut();
  thiss.GoogleAuth.disconnect();
};

1 个答案:

答案 0 :(得分:0)

这是由于未验证的域名引起的。

所有您需要验证的域名并在Oauth控制台中提供应用名称和网站地址

相关问题