jQuery 如何通过 API 查询搜索 Instagram?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11634881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How To Search Instagram via API Query?
提问by Jake
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.
我想构建一个由 Instagram 照片驱动的小型“即时图像搜索”应用程序。这就像 Google Instant,您可以在其中开始输入并在您输入更多字母时显示/更新结果。
You can see a live demo apppowered 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?
您可以看到由 Google 图片提供支持的实时演示应用程序。我知道这对于更大的引擎(Google、Yahoo!、Bing)是可能的,但我不知道 Instagram 是否允许这样做。任何熟悉 API 的人都可以提供这方面的帮助吗?
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.
如果无法通过有意义的 API 进行搜索。我只是想先在这里检查一下,因为有很多知识渊博的程序员。
回答by scumah
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:
首先,如果您不知道,已经有一个类似的(至少)Web 应用程序。话虽如此,让我们来看看答案:
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):
您需要获取您的 client_id,因为您需要它来调用 API(更多信息在这里)。您应该调用此端点(有关 Instagram API 端点的更多信息请阅读此处: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.
当然,更改SEARCH-TAG
用户输入,CLIENT-ID
使用您之前获得的输入和YOUR-CALLBACK
回调函数的名称。
The response to this call comes in JSONPand looks like this (Taken from the API's page):
对此调用的响应以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",
"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 :)
然后你只需要处理这个响应并用它做任何你想做的事情:)
回答by Arthur Flower
An important side note: instagram allows max 5000 queries for hour. This if you use the query with the app id. If you want to raise this limit, you can ask your users to authenticate. Then you can pass the the user access token. Hope this helps
一个重要的旁注:instagram 每小时最多允许 5000 次查询。如果您将查询与应用程序 id 一起使用。如果您想提高此限制,您可以要求您的用户进行身份验证。然后您可以传递用户访问令牌。希望这可以帮助