Instagram API-如何获得最近标记的媒体列表



嗨,社区我真的很新,我试图在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.intacearch.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/最近。。

感谢社区。

此问题已解决!

Instagram API标签搜索不返回任何

我认为你的问题在js 中

var sfield = $("#s");
var container = $("#photos");

您将jquery元素存储在一个变量中,稍后将对jquery元素调用jquery。将$(sfield)替换为sfield。也可以对容器执行此操作

最新更新