如何通过API查询搜索Instagram的? [英] How To Search Instagram via API Query?

查看:177
本文介绍了如何通过API查询搜索Instagram的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个小型的'即时影像搜索应用程序搭载的Instagram照片。这将是像谷歌即时你开始打字,结果在您键入更多字母显示/更新。

您可以看到一个现场演示应用搭载谷歌图片来代替。我知道这是可能的更大的引擎(谷歌,雅虎,必应),但我不知道,如果Instagram的将允许这一点。任何人都熟悉这个API的提供帮助?

如果这是不可能通过有意义的API进行搜索。我只是想检查这里首先因为有这么多的知识渊博的程序员。

解决方案

首先,和如果你不知道,还有的已经种相似(至少)的Web应用程序。话虽这么说,让我们去回答:

您需要让你CLIENT_ID 的,因为你需要它来调用API(更多信息的这里)。你应该打电话到这个端点(约Instagram的的API端点的此处,你应该阅读:P):

<$p$p><$c$c>https://api.instagram.com/v1/tags/SEARCH-TAG/media/recent?client_id=CLIENT-ID&callback=YOUR-CALLBACK

当然,改变搜索-TAG 用户输入,客户端ID 与一个你之前有和您的回调与你的回调函数的名称。

这一号召的响应进来 JSONP ,看起来像这样(从API​​的页面获取):

  {
    数据: [{
        类型:形象,
        过滤器:晨鸟,
        标签:雪],
        意见:{
            数据: [{
                created_time:1296703540,
                文:雪,
                从: {
                    用户名:emohatch
                    用户名:戴夫,
                    ID:1242695
                },
                ID:26589964
            },
            {
                created_time:1296707889,
                文:#snow
                从: {
                    用户名:emohatch
                    用户名:情绪哈奇,
                    ID:1242695
                },
                ID:26609649
            }],
            伯爵:3
        }
        标题: {
            created_time:1296703540,
            文:#Snow
            从: {
                用户名:emohatch
                ID:1242695
            },
            ID:26589964
        },
        喜欢:{
            伯爵:1,
            数据: [{
                用户名:mikeyk
                FULL_NAME:迈克·克里格
                ID:4,
                profile_picture:http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg
            }]
        },
        链接:http://instagr.am/p/BWl6P/
        用户: {
            用户名:emohatch
            profile_picture:http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg,
            ID:1242695,
            FULL_NAME:戴夫
        },
        created_time:1296703536,
        形象:{
            low_resolution:{
                URL:http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_6.jpg
                宽:306,
                高度:306
            },
            缩略图:{
                URL:http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_5.jpg
                宽:150,
                高度:150
            },
            standard_resolution:{
                URL:http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_7.jpg
                宽:612,
                高度:612
            }
        },
        ID:22699663,
        位置:空
    },
    ...
    ]
}
 

然后你只需要处理这种反应,做任何你想做的事情:)

I would like to build a small 'instant image search' app powered by Instagram photos. This would be like Google Instant where you start typing and results are displayed/updated as you type more letters.

You can see a live demo app powered by Google Images instead. I know this is possible with larger engines (Google, Yahoo!, Bing) but I have no idea if Instagram will allow this. Can anybody familiar with the API offer help on this?

If it's not possible to search via the API that makes sense. I just wanted to check here first since there are so many knowledgeable programmers.

解决方案

First of all, and in case you didn't knew, there's already one similar (at least) web app. That being said, let's go to the answer:

You need to get your client_id, since you need it to call the API (More info here). You should be making calls to this endpoint (More info about Instagram's API endpoints here, you should read this :P):

https://api.instagram.com/v1/tags/SEARCH-TAG/media/recent?client_id=CLIENT-ID&callback=YOUR-CALLBACK

Of course, change the SEARCH-TAG with user input, CLIENT-ID with the one you got before and YOUR-CALLBACK with your callback function's name.

The response to this call comes in JSONP and looks like this (Taken from the API's page):

{
    "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",
                "from": {
                    "username": "emohatch",
                    "username": "Emo Hatch",
                    "id": "1242695"
                },
                "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
    },
    ...
    ]
}

Then you just need to process this response and do whatever you want with it :)

这篇关于如何通过API查询搜索Instagram的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆