小编mlb*_*mlb的帖子

(仍未解决)授权Web客户端访问客户端和服务器端的用户Google日历?(使用Firebase和Google API)

我有一个火力地堡的web应用程序,
并希望这样的任何用户可以登录并授权我的web应用程序访问他的谷歌日历(读/写)在客户端服务器端(管理日历,当用户在线时,当他的下线).


客户端.
Google开发者控制台上创建API密钥OAuth 2.0客户端ID(Web应用程序)后,我实现了以下代码:

首先,通过Firebase Authentification登录Google

firebase.initializeApp({apiKey: 'MY_WEB_APP_API_KEY'})
var provider = new firebase.auth.GoogleAuthProvider()
provider.addScope('https://www.googleapis.com/auth/calendar')
firebase.auth().signInWithPopup(provider)
Run Code Online (Sandbox Code Playgroud)

并且,要求授权我的Web应用程序可以使用Google Api JS客户端访问用户的Google日历

// https://apis.google.com/js/api.js
gapi.load('client:auth2', () => {
  gapi.auth2.authorize({
      scope: 'https://www.googleapis.com/auth/calendar',
      client_id: 'MY_WEB_APPL_CLIENT_ID',
      prompt: 'none',
      access_type: 'offline',
      include_granted_scopes: true
    }, () => {
      gapi.client.init({
        discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest']
      }).then(()  => {
        return gapi.client.calendar.events.list({
          calendarId: 'ANY_USER_CALENDAR_ID' // example: …
Run Code Online (Sandbox Code Playgroud)

javascript google-api google-authentication google-api-nodejs-client firebase-authentication

7
推荐指数
1
解决办法
263
查看次数