首页 文章

RingCentral API CallLog在不同的时区提供响应

提问于
浏览
2

谢谢你看我的问题 . 我正在使用API下载RingCentral Call日志 . 但没有获得提供日期的准确通话记录 . 例如,如果我想在 2018-6-4 00:00:00 TO 2018-6-5 23:59:59 之间下载通话记录,那么它将从 2018-6-3 17:00:00 TO 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...!")

1 回答

  • 1

    登录RingCentral的时间戳是GTM时间 . 您只需转换为当地时间(-7小时)

相关问题