向Instagram搜索API添加分页[AJAX+;PHP]
stackoverflow的第一篇帖子! 使用此脚本的修改版本 我已将其更改为用户搜索,而不是标记搜索。。添加两个api调用,一个用于ID,另一个用于按用户名显示的图像 我见过其他使用分页的例子但不确定如何将其应用于我的当前代码。。instagram API非常新 请随意使用我的代码!这是一种很好的ajax方式,可以检索每个用户的照片为了便于阅读,我取出了卷曲部分。 我只想称之为每页20张照片谢谢。 instasearch.php向Instagram搜索API添加分页[AJAX+;PHP],php,ajax,pagination,instagram,instagram-api,Php,Ajax,Pagination,Instagram,Instagram Api,stackoverflow的第一篇帖子! 使用此脚本的修改版本 我已将其更改为用户搜索,而不是标记搜索。。添加两个api调用,一个用于ID,另一个用于按用户名显示的图像 我见过其他使用分页的例子但不确定如何将其应用于我的当前代码。。instagram API非常新 请随意使用我的代码!这是一种很好的ajax方式,可以检索每个用户的照片为了便于阅读,我取出了卷曲部分。 我只想称之为每页20张照片谢谢。 instasearch.php <?php header('Content-type: a
<?php
header('Content-type: application/json');
define("YOUR_TOKEN", 'TOKEN HERE');
$query = $_POST['q'];
$userid = 'https://api.instagram.com/v1/users/search?count=1&q=' . $query . '&access_token='. YOUR_TOKEN;
$clnum = mt_rand(1,3);
// function get_curl($url) WOULD GO HERE //
// SEARCH FOR ID //
$response = get_curl($userid);
if ($response){
foreach(json_decode($response)->data as $item){
$id = $item->id;
$user[] = array(
"id" => htmlspecialchars($id),
);
}
}
// SEARCH BY ID //
$api ='https://api.instagram.com/v1/users/' . $id . '/media/recent/?' . '&access_token='. YOUR_TOKEN . '&count=33';
$response2 = get_curl($api);
$images = array();
if($response2){
foreach(json_decode($response2)->data as $item){
$src = $item->images->standard_resolution->url;
$thumb = $item->images->thumbnail->url;
$url = $item->link;
$count = $item->likes->count;
$images[] = array(
"src" => htmlspecialchars($src),
"thumb" => htmlspecialchars($thumb),
"url" => htmlspecialchars($url),
"count" => htmlspecialchars($count)
);
}
}
print_r(str_replace('\\/', '/', json_encode($images)));
//if($likes)
//print_r(json_encode($likes));
//
die();
?>
ajax.js
$(document).ready(function(){
var sfield = $("#s");
var container = $("#photos");
var timer;
function instaSearch() {
$(sfield).addClass("loading");
$(container).empty();
var q = $(sfield).val();
$.ajax({
type: 'POST',
url: 'http://192.168.0.3/igpanel/image-select/instasearch.php',
data: "q="+q,
success: function(data){
$(sfield).removeClass("loading");
$.each(data, function(i, item) {
var ncode = '<span class="p"><span id="likes"><i style="color:#E74C3C" class="fa fa-heart"></i> '+data[i].count+' likes</span><!--<a href="'+data[i].url+'" target="_blank">--><img id="'+data[i].url+'" src="'+data[i].thumb+'"></a></span>';
$(container).append(ncode);
});
},
error: function(xhr, type, exception) {
$(sfield).removeClass("loading");
$(container).html("Error: " + type);
}
});
}
$(文档).ready(函数(){
var sfield=$(“#s”);
var容器=$(“#照片”);
无功定时器;
函数instaSearch(){
$(sfield).addClass(“加载”);
$(容器).empty();
var q=$(sfield.val();
$.ajax({
键入:“POST”,
网址:'http://192.168.0.3/igpanel/image-select/instasearch.php',
数据:“q=”+q,
成功:功能(数据){
$(sfield).removeClass(“加载”);
$。每个(数据、功能(i、项){
var ncode=''+数据[i].计数+'
<section id="sform">
<input type="text" id="s" name="s" class="form-control" placeholder="Enter Username..." autocomplete="off">
</section>
<div id="image_container">
<section id="photos"></section>
</div>