RingCentral API CallLog 在不同的时区给出响应
RingCentral API CallLog giving Response in a different time zone
感谢您查看我的问题。我正在使用 API 下载 RingCentral 通话记录。但没有获得所提供日期的准确通话记录。例如,如果我想在 2018-6-4 00:00:00 到 2018-6-5 23:59:59 之间下载通话记录,那么它会从 [= 下载通话记录14=]2018-6-3 17:00:00 至 2018-6-4 19 17:00:00。好像它要回到我提供的日期的 7 个小时。
这是我的代码:
from ringcentral import SDK
import csv
import json
import datetime
UserName = input("Please Enter Your UserName:")
Password = input("Please Enter Your Password:")
sdk = SDK(
'xxxxxxxxx', #App secret
'xxxxxxxxxxxxxx', #Client Secret
'https://platform.ringcentral.com')
platform = sdk.platform()
platform.login(
UserName,
'',
Password)
print("Login Successful...!")
From = input("Please Enter DateFrom (yyyy-mm-dd) :")
To = input("Please Enter DateTo (yyyy-mm-dd) :")
print("Please Wait...")
try:
from urllib import urlencode
except:
from urllib.parse import urlencode
query = {
'dateFrom': From + 'T00:00:00Z',
'dateTo': To + 'T00:00:00Z',
'direction': 'Outbound',
'type': 'Voice',
'view': 'Simple',
'perPage' : 1000
}
qs = urlencode(query)
res = platform.get('/restapi/v1.0/account/~/call-log?'+qs)
r = res.text()
csvfile = open("CallLog_" + From + " to " + To + '.csv', 'w')
cr = csv.writer(csvfile, dialect='excel', lineterminator='\r')
heading = ["Type","Direction","From","To","Name","Date","Time","Action", "Result", "Duration"]
cr.writerow (heading)
data =json.loads(r)
for item in data['records']:
Type = item['type']
Dirc = item['direction']
Fro = item['from']['phoneNumber']
Too = item['to']['phoneNumber']
Name = item['from']['name']
Dt = item['startTime'][0 : item['startTime'].find("T")]
Tm = item['startTime'][(item['startTime'].find("T"))+1 : item['startTime'].find(".")]
Act = item['action']
Res = item['result']
Dur = str(datetime.timedelta(seconds = item['duration']))
Row = [Type, Dirc, Fro, Too, Name, Dt, Tm, Act, Res, Dur]
cr.writerow (Row)
csvfile.close()
print("CallLog_" + From + "_to_" + To + ".csv" + " Downloaded successfully...!")
RingCentral 中记录的时间戳是 GTM 时间。您只需要转换为当地时间(-7 小时)
感谢您查看我的问题。我正在使用 API 下载 RingCentral 通话记录。但没有获得所提供日期的准确通话记录。例如,如果我想在 2018-6-4 00:00:00 到 2018-6-5 23:59:59 之间下载通话记录,那么它会从 [= 下载通话记录14=]2018-6-3 17:00:00 至 2018-6-4 19 17:00:00。好像它要回到我提供的日期的 7 个小时。 这是我的代码:
from ringcentral import SDK
import csv
import json
import datetime
UserName = input("Please Enter Your UserName:")
Password = input("Please Enter Your Password:")
sdk = SDK(
'xxxxxxxxx', #App secret
'xxxxxxxxxxxxxx', #Client Secret
'https://platform.ringcentral.com')
platform = sdk.platform()
platform.login(
UserName,
'',
Password)
print("Login Successful...!")
From = input("Please Enter DateFrom (yyyy-mm-dd) :")
To = input("Please Enter DateTo (yyyy-mm-dd) :")
print("Please Wait...")
try:
from urllib import urlencode
except:
from urllib.parse import urlencode
query = {
'dateFrom': From + 'T00:00:00Z',
'dateTo': To + 'T00:00:00Z',
'direction': 'Outbound',
'type': 'Voice',
'view': 'Simple',
'perPage' : 1000
}
qs = urlencode(query)
res = platform.get('/restapi/v1.0/account/~/call-log?'+qs)
r = res.text()
csvfile = open("CallLog_" + From + " to " + To + '.csv', 'w')
cr = csv.writer(csvfile, dialect='excel', lineterminator='\r')
heading = ["Type","Direction","From","To","Name","Date","Time","Action", "Result", "Duration"]
cr.writerow (heading)
data =json.loads(r)
for item in data['records']:
Type = item['type']
Dirc = item['direction']
Fro = item['from']['phoneNumber']
Too = item['to']['phoneNumber']
Name = item['from']['name']
Dt = item['startTime'][0 : item['startTime'].find("T")]
Tm = item['startTime'][(item['startTime'].find("T"))+1 : item['startTime'].find(".")]
Act = item['action']
Res = item['result']
Dur = str(datetime.timedelta(seconds = item['duration']))
Row = [Type, Dirc, Fro, Too, Name, Dt, Tm, Act, Res, Dur]
cr.writerow (Row)
csvfile.close()
print("CallLog_" + From + "_to_" + To + ".csv" + " Downloaded successfully...!")
RingCentral 中记录的时间戳是 GTM 时间。您只需要转换为当地时间(-7 小时)