简体   繁体   English

Google Latitude API会针对位置记录返回0结果

[英]Google Latitude API returns 0 results for location history

I'm trying to retrieve my location history using v1 (via OAuth 2.0) of the Google Latitude API , specifically the list method. 我正在尝试使用谷歌纵横API的 v1(通过OAuth 2.0)检索我的位置记录,特别是列表方法。

When attempting to retrieve records between two timestamps I do not get any locations back. 当试图在两个时间戳之间检索记录时,我没有得到任何位置。 However, I can retrieve my most recent locations (~860, only in the last 24 hours). 但是,我可以检索我最近的位置(~860,仅在过去24小时内)。 Trying to retrieve locations within the same time periods as those returned in the "recent" set also returns zero results. 尝试在与“最近”集合中返回的位置相同的时间段内检索位置也会返回零结果。

Does anyone know if I'm doing something wrong here, or if the issue lies in Latitude? 有谁知道我在这里做错了什么,或者问题出在Latitude? Can I retrieve my location history in this way? 我可以用这种方式检索我的位置记录吗?

Resolved: specified start and end timestamps need to be in milliseconds 已解决:指定的开始和结束时间戳需要以毫秒为单位

Here are some functions I used to help translate datetime objects to milliseconds: 以下是我用来帮助将datetime对象转换为毫秒的一些函数:

def dt_from_epoch(epoch):
    epoch = int(epoch)
    secs = epoch/1000
    mils = epoch - (secs*1000)

    dt = datetime.datetime.fromtimestamp(secs)
    dt.replace(microsecond=mils*1000)
    return dt

def dt_to_mils(dt):
    return int((time.mktime(dt.timetuple())*1000) + (dt.microsecond/1000))

Original examples 原始的例子

Test case script: 测试用例脚本:

# Service obtained in the usual OAuth 2.0 way using oauth2client and
# apiclient.discovery.build.
# Scope used: https://www.googleapis.com/auth/latitude.all.best

print "## Retrieve most recent history"
locs = service.location().list(granularity='best', max_results=1000).execute()
first = locs['items'][len(locs['items'])-1]
last= locs['items'][0]

first = datetime.datetime.fromtimestamp(int(first['timestampMs'][:-3]))
last = datetime.datetime.fromtimestamp(int(last['timestampMs'][:-3]))

print "%s - %s: %d" % (first.strftime('%Y-%m-%d %H:%M:%S'),
    last.strftime('%Y-%m-%d %H:%M:%S'), len(locs['items']))


print "## Retrieve history between %s and %s" % (
    first.strftime('%Y-%m-%d %H:%M:%S'), last.strftime('%Y-%m-%d %H:%M:%S'))

locs = service.location().list(
    granularity='best',
    min_time=int(time.mktime(first.timetuple())),
    max_time=int(time.mktime(last.timetuple())),
    max_results=1000
).execute()

results = len(locs['items']) if 'items' in locs else 0
print "%s - %s: %d" % (first.strftime('%Y-%m-%d %H:%M:%S'),
    last.strftime('%Y-%m-%d %H:%M:%S'), results)

Script output: 脚本输出:

## Retrieve most recent history
2012-08-25 23:02:12 - 2012-08-26 15:37:09: 846
## Retrieve history between 2012-08-25 23:02:12 and 2012-08-26 15:37:09
2012-08-25 23:02:12 - 2012-08-26 15:37:09: 0

JSON output of "most recent history": “最近历史”的JSON输出:

{
  "data": {
    "kind": "latitude#locationFeed",
    "items": [
      {
        "kind": "latitude#location",
        "timestampMs": "1345995443316",
        "latitude": (latitude),
        "longitude": (longitude)
      },
    (continues...)
    ]
  }
}

JSON output of "history between X and Y": “X和Y之间的历史”的JSON输出:

{
 "data": {
    "kind": "latitude#locationFeed"
  }
}

Looks like you're passing in seconds instead of milliseconds (since epoch). 看起来你在几秒钟而不是毫秒(自纪元以来)传递。 Specifically, note how you're dividing by 1000 with your [:-3]... 具体来说,请注意你如何用[:-3]除以1000 ...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM