【问题标题】:New calendar event, created using Google service account isn't sending invitaion email to the attendees使用 Google 服务帐户创建的新日历活动未向与会者发送邀请电子邮件
【发布时间】:2014-10-14 06:39:40
【问题描述】:

我正在使用 Google 的服务帐户在 Google 日历中创建一个新活动,并且我也将 sendNotifications 设置为 true,但创建活动后,邀请电子邮件不发送给与会者??

  # new event to be created
  event = {
    'summary'=> summary,
    'description'=> description,
    'start'=> {'dateTime' => datetime },
    'end' => {'dateTime' => datetime },
    'sendNotifications' => true,
    'sequence' => sequence,
    'reminders' => {
      'useDefault' => false,
      'overrides' => [
        {'minutes' => 60, 'method' => 'email'}
      ]
    },  
    'attendees'=> [
      {
        'email'=> email
      }
    ]
  }

  # build client
  client = Google::APIClient.new application_name: "Test", application_version: "0.0.1"
  key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file, key_secret)     

  client.authorization = Signet::OAuth2::Client.new(
    :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
    :audience => 'https://accounts.google.com/o/oauth2/token',
    :scope => 'https://www.googleapis.com/auth/calendar',
    :issuer => ENV['SERVICE_ACCOUNT_EMAIL'],
    :grant_type => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
    :access_type => 'offline',
    :signing_key => key
  )

  # fetch access token
  client.authorization.fetch_access_token!

  # create new event
  service = client.discovered_api('calendar', 'v3')
  client.execute(:api_method => service.acl.insert,
                 :parameters => {'calendarId' => 'primary'},
                 :body => JSON.dump(event),
                 :headers => {'Content-Type' => 'application/json'})

【问题讨论】:

  • 事件是未来创建的吗?我认为如果你在这里发布你的代码会很棒。
  • 是的,我将在未来创建一个活动。

标签: ruby-on-rails google-calendar-api service-accounts


【解决方案1】:

sendNotifications 是请求的属性,而不是事件的属性。在此处查看插入的文档:https://developers.google.com/google-apps/calendar/v3/reference/events/insert 您还可以尝试使用资源管理器查看请求的确切外观:https://developers.google.com/apis-explorer/#p/calendar/v3/(不要忘记在右上角进行身份验证)。

【讨论】:

  • 你是对的。我从事件哈希中删除了 sendNotifications 属性并将其添加为请求的参数。
猜你喜欢
  • 1970-01-01
  • 2017-09-30
  • 1970-01-01
  • 2017-09-02
  • 2012-04-27
  • 2015-12-18
  • 1970-01-01
  • 2019-12-15
  • 2021-03-29
相关资源
最近更新 更多