我想建立一个由Instagram照片驱动的小型“即时图像搜索”应用程序.这就像Google Instant,您可以在其中键入并在键入更多字母时显示/更新结果.
您可以看到由Google图片提供支持的live demo app.我知道这可以用更大的引擎(谷歌,雅虎,Bing),但我不知道Instagram是否允许这样做.任何熟悉API的人都可以提供帮助吗?
如果无法通过API搜索有意义的话.我只想先在这里查看,因为有这么多知识渊博的程序员.
解决方法
首先,如果您不知道,已经有
one similar(至少)网络应用程序.话虽这么说,让我们回答一下:
您需要get your client_id,因为您需要它来调用API(更多信息here).您应该拨打this endpoint(有关Instagram的API端点here的更多信息,您应该阅读:P):
https://api.instagram.com/v1/tags/SEARCH-TAG/media/recent?client_id=CLIENT-ID&callback=YOUR-CALLBACK
当然,使用用户输入更改SEARCH-TAG,使用之前获得的CLIENT-ID更改SEARCH-TAG,使用回调函数的名称更改YOUR-CALLBACK.
对此调用的响应发布于JSONP,看起来像这样(摘自API的页面):
{ "data": [{ "type": "image","filter": "Earlybird","tags": ["snow"],"comments": { "data": [{ "created_time": "1296703540","text": "Snow","from": { "username": "emohatch","username": "Dave","id": "1242695" },"id": "26589964" },{ "created_time": "1296707889","text": "#snow","username": "Emo Hatch","id": "26609649" }],"count": 3 } "caption": { "created_time": "1296703540","text": "#Snow","from": { "username": "emohatch","id": "1242695" },"id": "26589964" },"likes": { "count": 1,"data": [{ "username": "mikeyk","full_name": "Mike Krieger","id": "4","profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg" }] },"link": "http://instagr.am/p/BWl6P/","user": { "username": "emohatch","profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg","id": "1242695","full_name": "Dave" },"created_time": "1296703536","images": { "low_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_6.jpg","width": 306,"height": 306 },"thumbnail": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_5.jpg","width": 150,"height": 150 },"standard_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_7.jpg","width": 612,"height": 612 } },"id": "22699663","location": null },... ] }
然后你只需要处理这个响应,并用它做任何你想做的事:)