嗨社区我真的很新,我试图搜索Instagram上的帖子(这个应用程序将在我的网络应用程序中使用),我已经搜索了这几天的所有答案,并尝试社区提供的大部分代码。对我来说,这是一个死胡同。 这是我的完整代码
1.home.php
<head>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<div id="w">
<section id="sform">
<input type="text" id="s" name="q" class="sfield" placeholder="Enter a search tag..." autocomplete="off">
</section>
<section id="photos"></section>
</div>
</body>
2.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: 'instasearch.php',
data: "q="+q,
success: function(data){
$(sfield).removeClass("loading");
$.each(data, function(i, item) {
var ncode = '<div><h1>'+data[i].name+'</h1><p>'+data[i].mediacount+'</p></div>';
$(container).append(ncode);
});
},
error: function(xhr, type, exception) {
$(sfield).removeClass("loading");
$(container).html("Error: " + type);
}
});
}
$(sfield).keydown(function(e){
if(e.keyCode == '32' || e.keyCode == '188' || e.keyCode == '189' || e.keyCode == '13' || e.keyCode == '190' || e.keyCode == '219' || e.keyCode == '221' || e.keyCode == '191' || e.keyCode == '220') {
e.preventDefault();
} else {
clearTimeout(timer);
timer = setTimeout(function() {
instaSearch();
}, 900);
}
});
});
3.instasearch.php
header('Content-Type: application/json');
$client = "xxxxx";
$access_token = "xxxxxx";
$query = $_POST['q'];
$api = 'https://api.instagram.com/v1/tags/search?q='.$query.'&access_token='.$access_token.'';
function get_curl($url) {
if(function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
return $output;
} else {
return file_get_contents($url);
}
}
$response = get_curl($api);
$datang = array();
if($response){
foreach(json_decode($response)->data as $item){
$mediacount = $item->media_count;
$name = $item->name;
$datang[] = array(
"mediacount" => htmlspecialchars($mediacount),
"name" => htmlspecialchars($name),
);
}
}
print_r(str_replace('\\/', '/', json_encode($datang)));
die();
输出还可以,现在.. 下一步,我想改变这个
$api = 'https://api.instagram.com/v1/tags/search?q='.$query.'&access_token='.$access_token.'';
进入这个
$api = "https://api.instagram.com/v1/tags/'.$query.'/media/recent?access_token=".$access_token."";
并返回错误(从我的网络浏览器复制粘贴)
{
"pagination": {
"deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead"
},
"meta": {
"code": 200
},
"data": []
}
请社区,我该如何解决这个问题?有人吗?
我想在这里提到输出(至少是JSON)https://instagram.com/developer/endpoints/tags/
在GET / tags / {tag-name} / media / recent ..
谢谢社区。
答案 0 :(得分:1)
答案 1 :(得分:0)
我认为你的问题是在js
var sfield = $("#s");
var container = $("#photos");
您将jquery元素存储在变量中,稍后您将在jquery元素上调用jquery。用sfield替换$(sfield)。也为容器做