【问题标题】:Python Twitter API result does not match documentation: 'urls' fieldPython Twitter API 结果与文档不匹配:“urls”字段
【发布时间】:2015-05-18 02:09:21
【问题描述】:

我看到的推文状态格式与我预期的文档不同。

import twitter
python_client = get_client() #however you want to do this
tweet_id = 577280319092613121
print client.GetStatus(tweet_id).AsDict()['urls']

{u'https://t.co/8JgjULu4jB': u'https://instagram.com/p/0RSj3ooyL-/'}

但是文档(特别是here)认为 urls 字段中的每个条目都应该是这样的字典:

{
  "url": "https:\/\/t.co\/XdXRudPXH5",
  "expanded_url": "https:\/\/blog.twitter.com\/2013\/rich-photo-experience-now-in-embedded-tweets-3",
  "display_url": "blog.twitter.com\/2013\/rich-phot\u2026",
  "indices": [80, 103]
}

我是不是做错了什么?


编辑(first answer 之后):

我正在尝试使用 pymongo 在 MongoDB 中存储一些推文。最初我试图将 status.AsDict() 插入我的集合中,但 MongoDB 不允许在键中使用 . 字符。所以我有两个问题:

  1. 对于我的教育,为什么 python-twitter 模块使用这种存储结构而不是遵循文档(这对我来说似乎更“自然”)?

  2. 更实际地说,status.AsDict() 是否会在其他地方出现类似行为(重新调整 API 文档中的键/值)?

【问题讨论】:

标签: python twitter pymongo


【解决方案1】:

当您从AsDict() 数据中选择urls 时,它会以表单形式返回它们

{url: expanded_url}

【讨论】:

  • 是的,我注意到了!我意识到我的问题并不是特别清楚我想要什么。我会编辑。
猜你喜欢
  • 2017-01-28
  • 1970-01-01
  • 2021-02-07
  • 2016-06-14
  • 2018-11-14
  • 2019-06-21
  • 2021-08-06
  • 1970-01-01
  • 2017-07-14
相关资源
最近更新 更多