【问题标题】:Firebase Auth and Caledar APIFirebase 身份验证和 Caledar API
【发布时间】:2020-07-02 08:38:22
【问题描述】:

我正在尝试登录用户并在他们的日历中创建一个事件。

我正在使用Firebase AuthGoogle Calendar API。我不确定如何使用 Firebase 访问令牌为用户创建事件。

 <script type="text/javascript">
      initApp = function() {
        firebase.auth().onAuthStateChanged(function(user) {
          if (user) {
            user.getIdToken().then(function(accessToken) {
            //how can I use this accessToken to create event in the calendar?
            });
          } else {}
        }, function(error) {});
      };

      window.addEventListener('load', function() {
        initApp();
      });
    </script>

我有一个可以登录用户的脚本,并且我有一个可以创建事件的脚本(代码未发布,因为代码与附加的链接非常相​​似)。如何将这两个任务结合起来?

通过阅读文档,我知道我必须将日历范围和发现文档添加到身份验证脚本中。但是,我正在为接下来的步骤而苦苦挣扎。

感谢您的帮助!

【问题讨论】:

    标签: firebase firebase-authentication google-calendar-api google-oauth google-api-js-client


    【解决方案1】:

    您不能使用 Firebase ID 令牌调用 Google 日历 API。

    您需要使用 Google JS library 登录 Google 并致电 calendar APIs。然后,您可以获取 Google ID 令牌令牌以使用 Firebase 登录。

    // Build Firebase credential with the Google ID token.
    const credential = firebase.auth.GoogleAuthProvider.credential(
        googleUser.getAuthResponse().id_token);
    // Sign in with credential from the Google user.
    firebase.auth().signInWithCredential(credential)
      .then((authResult) => {
        // User signed in with Firebase.
      })
      .catch((error) => {
        // Error while signing in.
      });
    

    【讨论】:

      猜你喜欢
      • 2019-08-17
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多