【问题标题】:Cannot read property 'currentUser' of undefined.Is googleUser value same as currentUser in Google oauth2?无法读取未定义的属性“currentUser”。googleUser 值是否与 Google oauth2 中的 currentUser 相同?
【发布时间】:2019-04-15 14:33:01
【问题描述】:

googleUser 的值是否与 Google 中的 currentUser auth2 相同?

componentDidMount() {

    window.gapi.load("client:auth2", () => {
      window.gapi.client
        .init({
          clientId:
            'CLIENT-ID.apps.googleusercontent.com',
          scope: "email"
        })
        .then(() => {
          this.auth2 = window.gapi.auth2.getAuthInstance()


          console.log('Current User Details :' , this.auth2.currentUser.Ab);
          console.log(this.auth2);

        });

       console.log(this.auth2.currentUser);
    }); 
  }

【问题讨论】:

    标签: reactjs oauth-2.0 google-oauth


    【解决方案1】:

    一个 GoogleUser 对象代表一个用户帐户。 GoogleUser 对象通常通过调用 GoogleAuth.currentUser.get() 获得。

    GoogleAuth.currentUser.get() 返回代表当前用户的 GoogleUser 对象。请注意,在新初始化的 GoogleAuth 实例中,当前用户尚未设置。使用 currentUser.listen() 方法或 GoogleAuth.then() 获取初始化的 GoogleAuth 实例。

    https://developers.google.com/api-client-library/javascript/reference/referencedocs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-26
      • 2018-09-25
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2011-08-25
      • 1970-01-01
      相关资源
      最近更新 更多