Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用ruby outlook创建日历事件_Ruby On Rails_Ruby_Calendar_Outlook Restapi_Outlook Calendar - Fatal编程技术网

Ruby on rails 使用ruby outlook创建日历事件

Ruby on rails 使用ruby outlook创建日历事件,ruby-on-rails,ruby,calendar,outlook-restapi,outlook-calendar,Ruby On Rails,Ruby,Calendar,Outlook Restapi,Outlook Calendar,我正在尝试在日历中创建一个事件 我可以通过以下文档获取所有数据,如日历、联系人和电子邮件 , 但是当尝试使用ruby\u创建事件时,outlook会出现以下错误 {"ruby_outlook_error"=>401, "ruby_outlook_response"=>{"error"=>{"code"=>"InvalidAudience", "mess

我正在尝试在日历中创建一个事件

我可以通过以下文档获取所有数据,如日历、联系人和电子邮件

,

但是当尝试使用ruby\u创建事件时,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

您的问题是您获取的令牌使用了,但现在您正试图通过Outlook API创建一个偶数。您不能对Outlook端点使用为
Graph(“aud”:“Graph.microsoft.com”)
颁发的
令牌。您需要一个带有“
”aud“:“outlook.office.com”
”的令牌。最好使用图形API本身,使用创建事件,因为您已经从中获取了令牌

为此,首先创建
MicrosoftGraph
对象

然后创建事件-


您的问题是您获取的令牌使用了,但现在您正试图通过Outlook API创建一个偶数。您不能对Outlook端点使用为
Graph(“aud”:“Graph.microsoft.com”)
颁发的
令牌。您需要一个带有“
”aud“:“outlook.office.com”
”的令牌。最好使用图形API本身,使用创建事件,因为您已经从中获取了令牌

为此,首先创建
MicrosoftGraph
对象

然后创建事件-


我认为您的问题是您获取的令牌使用了,但现在您正试图通过Outlook API创建一个偶数。您不能对Outlook终结点使用为Graph(“aud”:”)颁发的令牌。您需要一个带有“aud”:”的令牌。您好@Gautam,谢谢您的回复,我如何才能获得带有“aud”:“Outlook.office.com”的令牌“你为什么要这样做?更好的方法是使用graph API本身来创建事件,因为您已经从中获取了令牌。让我知道你是否能用这个?我有它的工作代码,我可以将它发布为asnwer。是的,这是一个好主意,但我没有找到在其中创建事件的代码[Documentation,这是关于获取数据的。是的@Gautam,我使用的是microsoft_graph Gei我想你的问题是,你获取的令牌使用的是,但现在你正试图通过Outlook API创建一个偶数。你不能对Outlook端点使用为graph(“aud”:”)发布的令牌。你需要一个带有“aud”:”的令牌“.Hi@Gautam,感谢您对此的回复,我如何才能获得带有“aud”的令牌”:“outlook.office.com”为什么要这样做?更好的方法是使用graph API本身来创建事件,因为您已经从中获取了令牌。请告诉我您是否可以使用?我有可用的代码,可以将其发布为asnwer。是的,这是一个很好的主意,但我没有在中找到创建事件的代码[Documentation,这是关于获取数据的。是的@Gautam,我正在使用microsoft\u graph gem
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