简体   繁体   中英

Use jquery and ajax to search instagram api by tag

I want to be able to have users input a tag and see results of recent media pertaining to that tag. I have tried this code but I'm getting an error in the Chrome Console.

" https://api.instagram.com/v1/tags//media/recent?callback=jQuery224041941550…24017687.51352a5.571b3b1e6a9945eea4745b7bea5d38f2&count=10&_=1465951645890 "

 var token = '24017687.51352a5.571b3b1e6a9945eea4745b7bea5d38f2', num_photos = 10; var hashtag = $("input.form-control").val(); // hashtag without # symbol $(function() { "use strict"; $('.input-group').on('submit', function(e) { e.preventDefault(); $.ajax({ url: 'https://api.instagram.com/v1/tags/' + hashtag + '/media/recent', dataType: 'jsonp', type: 'GET', data: { access_token: token, count: num_photos }, success: function(data) { console.log(data); for (x in data.data) { $('.thumbnail').append('<img src="' + data.data[x].images.standard_resolution.url + '">'); } }, error: function(data) { console.log(data); } }); }); }); 

According to the link you posted, it looks like hashtag is not being passed into the ajax request? Note there should be a string between /tags/ and /media/ in

https://api.instagram.com/v1/tags/NEED_HASHTAG_STRING_HERE/media/recent?callback=jQuery224041941550…24017687.51352a5.571b3b1e6a9945eea4745b7bea5d38f2&count=10&_=1465951645890

After I added a hashtag in with the complete access_token :

https://api.instagram.com/v1/tags/plane/media/recent?access_token=24017687.51352a5.571b3b1e6a9945eea4745b7bea5d38f2

I got:

{"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": []}

However, that's because the hashtag "plane" was not used in the last 20 photos of your Sandbox account. So try using a hashtag that you actually used recently.

In short, you needed to pass in the hashtag string with the access_token . I've only targeted the ajax side of things. You may also want to double check why your hashtag string is not being passed in or why $("input.form-control").val() is not being read, or anything related to your submit form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM