为什么我不能使用JSON API在Ubuntu软件中心获得此应用的所有评论?
阅读本文后我有一个问题: 是否有适用于软件中心的Web API?
我试图了解Ubuntu软件中心的JSON端点。
此JSON列出了软件中心提供的所有应用程序: http : //software-center.ubuntu.com/api/2.0/applications/any/ubuntu/any/any/
很酷……现在我需要为一个应用程序获得所有评论!
所以我选择一个应用程序并从JSON文件中获取其packages_name
:
{ "status": "Published", "package_name": "splashtop-streamer", "video_embedded_html_urls": [ "http://myapps.developer.ubuntu.com/dev/apps/1804/video/264a5fb11b60410a3a7d03bebdd1fcccd0cf5a72/" ],....
这里的package_name
是splashtop-streamer
。
要获取vlc
应用程序的所有评论,我只需执行以下操作: https : //reviews.ubuntu.com/reviews/api/1.0/reviews/filter/any/ubuntu/any/any/vlc
但对于splashtop-streamer
应用我不能: https : splashtop-streamer
它只返回这个:
[]
如果你看看splashtop-streamer 在线,你会发现它确实有评论。 那么为什么API会返回一个空列表呢?
这并不明显,但APIfilter使用origin指定应用程序是来自ubuntu档案还是PPA。 因此,对于商业应用程序,通过’ubuntu’过滤会得到零结果。 你想要的是:
http://reviews.ubuntu.com/reviews/api/1.0/reviews/filter/any/any/any/any/splashtop-streamer/ http://reviews.ubuntu.com/reviews/api/1.0/reviews/filter/any/any/any/any/splashtop-streamer/page/2/
等等
请注意,还有一个小包装器可以让您的代码更清洁,如果您需要它:
$ bzr branch lp:~rnr-developers/rnr-server/rnrclient $ cd rnrclient && virtualenv venv && venv/bin/python setup.py install && venv/bin/python >>> from rnrclient import RatingsAndReviewsAPI >>> api = RatingsAndReviewsAPI("http://reviews.ubuntu.com/reviews/api/1.0") >>> api.server_status() u'ok' >>> streamer_reviews = api.get_reviews(packagename='splashtop-streamer') >>> len(streamer_reviews) 10 >>> streamer_reviews = api.get_reviews(packagename='splashtop-streamer', page=2) ...