【发布时间】:2020-01-30 22:38:37
【问题描述】:
负责为现有的 Flutter 应用添加云功能。云功能的目标是每隔一段时间运行一次,看看用户帐户的 Google 日历中是否有即将发生的事件。
用户创建帐户并使用 Google 登录插件登录,然后存储在 firebase 中。
我已将所需的范围添加到 GoogleSignIn 对象
static GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'https://www.googleapis.com/auth/calendar.events.readonly',
],
);
登录过程
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
//update user table in firebase
此时,Google 登录过程会返回一个 访问令牌,我已将其存储在 firebase 中以供以后在云功能中使用。
我有来自 Google Developer Console 中 Web 应用程序/云功能 API 项目的客户端 ID 和客户端密码。
现在,我不确定如何使用 googleapis / 日历节点项目来使用 此访问令牌 进入该用户的日历。
所有示例似乎都希望我再次使用范围创建另一个 oauth2 客户端以检索令牌,但显然用户不会这样做,因为当用户不使用应用程序。
我是否需要创建一个服务帐户,然后才能代表用户访问这些日历?这甚至可以做到吗?我正在努力通过 Google 文档找到答案。
【问题讨论】:
标签: firebase google-api google-cloud-functions google-calendar-api google-signin