簡體   English   中英

Google Actions-訪問日歷api以插入事件列表

[英]Google Actions-Access to calendar api to insert list of events

用戶已經使用 Google Actions 的 google 登錄獲得了他的 gmail 帳戶的授權。現在我需要向用戶的 google 日歷插入事件列表,但我面臨一些問題或不知道如何構建它。我非常日歷 api 的新手,所以請任何人指導我如何解決它。

    const {google} = require('googleapis');
        var calendar = google.calendar('v3');
        const SCOPES = ['https://www.googleapis.com/auth/calendar'];
        const client_secret = "xyz"; 
        const client_id     = "xyz";
        const redirect_uris ="xyz";
        const oAuth2Client = new google.auth.OAuth2(
          client_id, client_secret, redirect_uris);
        oAuth2Client.setCredentials({
         access_token: 'ACCESS TOKEN HERE'
       });
var event = {
  'summary': 'Google I/O 2015',
  'location': '800 Howard St., San Francisco, CA 94103',
  'description': 'A chance to hear more about Google\'s developer products.',
  'start': {
    'dateTime': '2015-05-28T09:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'end': {
    'dateTime': '2015-05-28T17:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
};
calendar.events.insert({
  auth: oAuth2Client,
  calendarId: 'primary',
  resource: event,
}, function(err, event) {
  if (err) {
    console.log('There was an error contacting the Calendar service: ' + err);
    return;
  }
});
  1. 如何使用從 google 操作收到的 idtoken 訪問用戶的 google 日歷?
  2. 如何在用戶的日歷中插入多個事件?

您使用 Google Sign In for Assistant 獲得的 id 令牌不足以讓您訪問他們的日歷。 您將需要訪問令牌或身份驗證令牌。 雖然 Google Sign In 對此有所幫助 - 它不是完整的圖片,並且解決方案可能有點復雜。

通常,您需要執行以下操作:

  1. 您需要確保用於智能助理的 Google Cloud 項目已開啟日歷 API。 您將通過 Cloud Dashboard 的API 庫執行此操作。

  2. 您還需要通過 Cloud Dashboard 的Credentials頁面為 Web 應用程序(誠實)創建 OAuth 2.0 客戶端 ID 密鑰

  3. 有了這些,再加上 Google 登錄,您可以創建混合登錄策略,讓用戶登錄並授權您的操作使用正確的范圍訪問他們的日歷。

  4. 在登錄過程結束時,您將(最終)獲得訪問令牌和刷新令牌。 您將使用用戶的 Google ID 作為鍵將其存儲在某種類型的數據存儲區或數據庫(例如 Firebase Firestore)中。

  5. 然后,當他們訪問您的操作時,您可以從 ID Token 中獲取他們的 Google ID,在您的數據庫中查找他們的訪問令牌,並執行日歷命令。

有關過程的更完整討論,請參閱此 StackOverflow 帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM