Создать событие каландра, используя ruby outlook - PullRequest
0 голосов
/ 18 февраля 2020

Я пытаюсь создать событие в Calander,

Я могу получить все данные, такие как Calander, контакты и электронные письма, следуя приведенным ниже документам,

https://docs.microsoft.com/en-us/outlook/rest/ruby-tutorial ,

Но при попытке создать событие, используя ruby_outlook, появляется ошибка ниже

  {"ruby_outlook_error"=>401, 
   "ruby_outlook_response"=>{"error"=>{"code"=>"InvalidAudience", "message"=>"The audience claim value is invalid 'aud'.", 
   "innerError"=>{"requestId"=>"75984820-5241-11ea-b6fc-fc4dd44c1550", "date"=>"2020-02-18T11:26:08"}}}}

Ниже приведен код для создания события

def def index
   token = get_access_token   //getting access token
   if token
      outlook_client = RubyOutlook::Client.new
      event_payload = 
      {
         "Subject": "Discuss the Calendar REST API",
        "Body": {
        "ContentType": "HTML",
        "Content": "I think it will meet our requirements!"
        },
        "Start": {
        "DateTime": "2020-03-03T18:00:00",
        "TimeZone": "Pacific Standard Time"
        },
        "End": {
        "DateTime": "2020-03-03T19:00:00",
        "TimeZone": "Pacific Standard Time"
        },
        "Attendees": [
        {
        "EmailAddress": {
        "Address": "john@example.com",
        "Name": "John Doe"
        },
        "Type": "Required"
        }
        ]
      }
      outlook_client.create_event(token, event_payload, nil, 'user@domain.com')
   end
end

1 Ответ

2 голосов
/ 18 февраля 2020

Ваша проблема в том, что выбранный токен использовал Microsoft graph API , но теперь вы пытаетесь создать четное через Outlook API. Вы не можете использовать token, выданный для Graph ("aud": "graph.microsoft.com") для конечной точки Outlook. Токен с "aud": "outlook.office.com" .Better - это использование самого API графа, использующего graph gem для создания события, поскольку токен уже получен из него.

Для сначала выполните создание MicrosoftGraph объекта

def create_service_auth
  access_token = get_access_token
  callback =  Proc.new do |r|
    r.headers['Authorization'] = "Bearer #{access_token}"
    r.headers['Content-Type']  = 'application/json'
    r.headers['X-AnchorMailbox'] = "#{ email_of_calendar_for_which_to_create_the_event }"
  end
  @graph = ::MicrosoftGraph.new(base_url: 'https://graph.microsoft.com/v1.0',
                            cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, 'metadata_v1.0.xml'),
                              &callback)
end

Затем создайте событие -

def create_event
  event = {
    subject: summary,
    body: {
      content_type: "HTML",
      content: description
    },
    start: {
      date_time: start_time,
      time_zone: timezone
    },
    end: {
      date_time: end_time,
      time_zone: timezone
    },
    response_requested: true,
    organizer: {emailAddress: { name: "#{organizer.full_name}", address: email_of_calendar_for_which_to_create_the_event }},
    attendees: [
      {
        email_address: {
          address: attendee_email,
          name: "#{attendee.full_name}"
        },
        type: "required"
      }
    ]
  }

  result = @graph.me.events.create(event)
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...