简体   繁体   English

Python Office365 API-TimeZone保持本地时间

[英]Python Office365 API - TimeZone stays at Local Time

I have this python code below and it works for creating a event in Outlook Calendar. 我下面有这个python代码,它可用于在Outlook日历中创建事件。 The example below has Start and End time from 3pm to 4pm (I think UTC timezone) 下面的示例的开始和结束时间为下午3点到下午4点(我认为是UTC时区)

We have users from different regions (Pacific, Mountain, Central... times). 我们有来自不同地区(太平洋,山区,中部...时间)的用户。 What I try to accomplish is the time always be local time. 我试图做到的是,时间总是本地时间。 No matter where the user account from it should also default to 3pm to 4pm in their Outlook. 无论用户帐户来自何处,其Outlook中的默认值都应为下午3点至下午4点。

Thanks in advance and please let me know if I need to clarify any of this. 在此先感谢您,如果我需要澄清其中的任何一个,请告诉我。

# Set the request parameters
url = 'https://outlook.office365.com/api/v1.0/me/events?$Select=Start,End'
user = 'user1@domain.com'

pwd = getpass.getpass('Please enter your AD password: ')


# Create JSON payload
data = {
  "Subject": "Testing Outlock Event",
  "Body": {
    "ContentType": "HTML",
    "Content": "Test Content"
  },
  "Start": "2016-05-23T15:00:00.000Z",
  "End": "2016-05-23T16:00:00.000Z",
      "Attendees": [
    {
      "EmailAddress": {
        "Address": "user1@domain.com",
        "Name": "User1"
      },
       "Type": "Required"  },

       {
      "EmailAddress": {
        "Address": "user2@domain.com",
        "Name": "User2"
      },
       "Type": "Optional"  }
  ]
}

json_payload = json.dumps(data)

# Build the HTTP request
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url, data=json_payload)
auth = base64.encodestring('%s:%s' % (user, pwd)).replace('\n', '')
request.add_header('Authorization', 'Basic %s' % auth)
request.add_header('Content-Type', 'application/json')
request.add_header('Accept', 'application/json')
request.get_method = lambda: 'POST'
# Perform the request
result = opener.open(request)

First of all, there's no point of creating a meeting on the same time at different timezones. 首先,没有必要在不同时区同时创建会议。

If you really want to do so, you'll need to create separate meeting requests per the timezone of the attendees, the JSON format would be something like below, 如果您确实要这样做,则需要按与会者所在的时区创建单独的会议请求,JSON格式如下所示,

var body = new JObject
        {
            {"Subject", "Testing Outlock Event"},
            {"Start", new JObject { { "DateTime", "2016-03-24T15:00:00"}, { "TimeZone", "Pacific Standard Time" } } },
            {"End", new JObject { { "DateTime", "2016-03-24T16:00:00"}, { "TimeZone", "Pacific Standard Time" } } }
        };

Note you need to remove the capital 'Z' from the time, so that it'll be shown in the local time tone specified by the "TimeZone" attribute. 请注意,您需要从时间中删除大写字母“ Z”,以便以“ TimeZone”属性指定的本地时间音调显示。

The workaround above needs to know the timezone of all the attendees, I'm not sure if this can be done pragmatically. 上面的解决方法需要知道所有与会者的时区,我不确定是否可以务实地做到这一点。 If not, it might not make much sense if you have tones of attendees. 如果没有,那么如果您有与会者的音调可能就没有多大意义。

The "ideal" way of achieving your requirement is giving the time without specifying the timezone, so that it'll be shown at the same time with different timezone. 达到要求的“理想”方法是在不指定时区的情况下给出时间,以便在不同的时区同时显示该时间。

However, it's not supported yet, but you can vote here https://officespdev.uservoice.com/forums/224641-general/suggestions/12866364-microsoft-graph-o365-unified-api-create-events-w 但是,尚不支持,但是您可以在这里投票https://officespdev.uservoice.com/forums/224641-general/suggestions/12866364-microsoft-graph-o365-unified-api-create-events-w

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 Python office365 API 下载 Sharepoint Docx 文件 - Download Sharepoint Docx file via Python office365 API 使用 Python 访问 Office365 Sharepoint REST 端点(Python 的 Office365 Sharepoint REST 客户端) - Accessing Office365 Sharepoint REST EndPoints using Python (Office365 Sharepoint REST client for Python) 使用 office365 API 将文件上传到 Sharepoint 中的子文件夹 - Upload file to a subfolder in Sharepoint with office365 API office365管理活动api没有可供下载的内容 - office365 management activity api no content available to download Python:如何将电子邮件文本正文传递给Office365电子邮件 - Python: How to pass email text body to Office365 Email Office365 smtp 服务器不响应python中的ehlo() - Office365 smtp server does not respond to ehlo() in python 通过 Python 单点登录访问 Office365 SharePoint - Access Office365 SharePoint with Single Sign-On via Python python smtplib 未发送 email 与 office365 地址 - python smtplib not sending email with office365 address 解析 Python 中 Office365 使用报告的 OData 返回时出现问题 - Problems parsing OData return for Office365 usage report in Python 使用Office365 python库`python-o365`发送电子邮件 - Send email with Office365 python library `python-o365`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM