【问题标题】:Tag feed not sorted by tagging time标记供稿未按标记时间排序
【发布时间】:2015-04-11 10:13:28
【问题描述】:

Instagram 开发者文档说 this 关于 /tags/<tag_name>/media/recent 提要:

请注意,此媒体是按使用此标签标记媒体的时间排序的,而不是按发布的顺序排列的。

但是,实际情况似乎并非如此。如果我请求混合使用标题和 cmets 的标签的数据,然后提取相关标题/评论的发布时间,我会得到:

[('caption  ', '2015-04-10 07:55:48'),
 ('caption  ', '2015-04-10 07:46:31'),
 ('caption  ', '2015-04-08 17:16:38'),
 ('caption  ', '2015-04-07 12:20:02'),
 ('caption  ', '2015-04-07 05:35:47'),
 ('comment 5', '2015-04-11 01:53:33'),
 ('caption  ', '2015-04-04 15:27:32'),
 ('caption  ', '2015-04-04 14:11:27'),
 ('comment 0', '2015-04-06 00:49:15'),
 ('caption  ', '2015-04-04 01:16:52'),
 ('caption  ', '2015-04-03 23:47:48'),
 ('caption  ', '2015-04-03 23:45:02'),
 ('comment 2', '2015-04-03 18:48:37'),
 ('comment 0', '2015-04-03 07:35:28'),
 ('comment 1', '2015-04-06 16:11:31'),
 ('caption  ', '2015-04-02 05:38:34'),
 ('comment 0', '2015-04-04 19:57:26'),
 ('comment 5', '2015-04-02 01:05:38'),
 ('caption  ', '2015-04-01 15:51:37'),
 ('caption  ', '2015-04-01 15:47:50')]

您可以清楚地看到这些数据是乱序的:即使触发更新的标签是在稍后的评论中添加的,项目也是按发布顺序显示的。

此排序至关重要,因为不可理解的原因,实时标签通知不包括已标记的媒体项的 ID,这意味着我们必须随后请求最近标记的提要以获取该信息。如果我们不能依赖排序,那么如果不每次都重新解析整个标签流,就无法可靠地提取已标记的项目,这显然是不可扩展的。

关于如何通过标记时间获得真正的排序的任何想法或建议?

这应该不相关,但这是我用来提取上述排序的 Python 代码:

def get_date(timestamp):
  return datetime.datetime.fromtimestamp(float(timestamp))

def tagged_time(tag):
  url = 'https://api.instagram.com/v1/tags/{tag_name}/media/recent?client_id={client_id}'
  data = requests.get(url.format(tag_name=tag, client_id=my_client_id)).json()
  times = []
  for item in data['data']:
    if tag in item['caption']['text'].lower():
      times.append(('caption  ', item['caption']['created_time']))
    else:
      for i, c in enumerate(item['comments']['data']):
        if tag in c['text'].lower():
          times.append(('comment %s' % i, get_date(c['created_time'])))
          break
      else:
        times.append('not found')
  return times

【问题讨论】:

  • 没错。我也面临着最近开始发生的同样情况。不过,它按预期工作。 ://

标签: instagram


【解决方案1】:

文档已过时,Instagram 最近进行了更改,现在他们按照片发布时间排序,而不是按添加主题标签的时间排序。

以下是 Instagram 发布的公告: https://twitter.com/instagram/status/581493922620309504

【讨论】:

  • 这里讲的是标签页。我们是否确定 API 更改是其预期结果?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 2022-11-01
  • 2021-10-26
  • 1970-01-01
  • 2010-12-25
相关资源
最近更新 更多