"Encountering problems with location search function on Instagram API for retrieving posts

I've been working on integrating two APIs – Instagram and Google Maps.

While I've managed to get everything functioning smoothly, there's an issue with displaying "up to 20 pictures" around a specific location. I'm unsure why this inconsistency is occurring.

Depending on the distance specified in the query, sometimes I receive up to 12 pictures, other times 13, and occasionally only 3. For example, without using any distance parameter, I can see up to 12 pictures; setting the distance to 1000 yields about 8 pictures, but increasing it to 2000 or more results in only 1-3 images at most.

If anyone has insight on how I can address this problem, I'd appreciate your input. Below is an excerpt of the code responsible for this functionality. Despite knowing that there are over 20 pictures available in the area, they aren't all displayed. For instance, a picture I posted yesterday isn't showing, and currently, only 10 posts are visible from that location.

    function retrieveData() {
    return $.ajax({
url: "https://api.instagram.com/v1/media/search?lat=59.24642059999999&lng=18.0613027&distance=1000&access_token=MY_ACCESS_TOKEN_CODE", 
dataType: 'jsonp', 
cache: false });
        }

var dataPromise = retrieveData();
dataPromise.done(function(data) {
    for (var i = 0; i < 20; i++) {
    $(".myLocation").append("<li><img src='" + data.data[i].images.thumbnail.url + "'></img>" 
                                              + "<p class='thumblikes'><img src='img/likeicon.png'></img>" + data.data[i].likes.count + "</p>" 
                                              + "</li>");

Thank you for your assistance!

Answer №1

When using the Instagram API, it is important to note that only a maximum of 20 photos can be returned per API call. Unfortunately, Instagram does not provide pagination for this particular API call. However, you can utilize the max_timestamp API url param to retrieve the next set of 20 photos.

To implement pagination, simply extract the data.created_time value of the last photo from the initial API call. Use this value as the max_timestamp= parameter in the API URL for subsequent calls to fetch the next batch of 20 photos and continue this process as needed.

If you are looking for an example of location search with pagination, you can check out this implementation:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sleek transition-ready zoom functionality for THREE JS with clickable controls

Hey there, I've been attempting to animate a transition between scenes in THREE js for quite some time now. I have successfully cleared the scene and recreated the next one, but the transition between them is proving to be quite challenging. I have cr ...

Showing a loading animation inside an HTML element

I have a main webpage that contains several buttons. Each button, when clicked, loads a specific target page as an object within a div on the main page. The "target" refers to the page that will be displayed within the object. <script> .... chec ...

Extremely sluggish change identification in combination Angular application

We are encountering consistent issues with slow change detection in our hybrid AngularJS / Angular 8 app, especially when dealing with components from different versions of the framework. The problem seems to arise when using older AngularJS components wit ...

Semantic-release failing to generate a new version update for package

I'm in the process of setting up semantic release for my NPM package to automate deployment with version updates. However, after migrating from an old repo/npm package to a new one, I'm facing issues with semantic versioning not creating a new re ...

Encountering a 404 error in Codeigniter when making an AJAX call

After successfully implementing an upload form with ajax, I encountered some issues when attempting to delete uploaded photos. Initially, I received a "csrf protection error," which led me to disable csrf protection, only to then encounter a "404 not found ...

Learn the process of submitting tag values using JohMun/vue-tags-input feature

I am a beginner in Vue.js and I am looking to implement an input field with multiple tags (user skills) using a Vue.js component. Although I have managed to make it work, I am struggling to figure out how to submit the tags in a form. Below is my code: T ...

Creating a custom design for legends in Chart.js

I'm currently working on a project using chart.js and I'm trying to customize the label/legend styling for my chart. My goal is to replace the rectangular legend with a circular one. I've come across the suggestion of creating a custom legen ...

Send a request to the uClassify API using the Node request module

I'm currently working on integrating the uClassify API into my Node project, but I'm encountering some issues with my code. Here's what I have so far: const req = JSON.stringify('Hello, my love!'); const options = { body: ...

Calculating variables in JavaScript

Explanation from Mozilla Documentation: console.log((function(...args) {}).length); // The result is 0 because the rest parameter is not counted console.log((function(a, b = 1, c) {}).length); // The result is 1 because only parameters before th ...

Guide to creating a Map with typescript

I've noticed that many people are converting data to arrays using methods that don't seem possible for me. I'm working with React and TypeScript and I have a simple map that I want to render as a list of buttons. Here is my current progres ...

Adding properties to a class object in Javascript that are integral to the class

Recently, I've been contemplating the feasibility of achieving a certain task in JavaScript. Given my limited experience in the realm of JavaScript, I appreciate your patience as I navigate through this. To illustrate what I am aiming for, here' ...

verification tool for a less file's syntax

Searching for a tool to validate a specific less file at the syntax level. The issue lies in the validator not recognizing dependencies or detecting declared mixins. Many existing less processors do not work due to missing dependencies that cannot be prov ...

Conceal the results of echoing json_encode

One dilemma I encountered was passing an array from PHP to JavaScript using json_encode and ajax. The only method that seemed available was to use echo json_encode($var) This approach printed out the contents of $var on the page due to the echo statement ...

Error: Surprising token found in ReactJS application on CodeSandbox

Encountering an unexpected token on line 5 error in my ReactJS project when testing it on CodeSandbox. Interestingly, the app runs smoothly without errors on my local machine. import React, { Component } from 'react'; import Header from ' ...

Using React.js to compute dates based on user-inputted dates

Today was dedicated to tackling the coding challenge of creating a function. I'm currently working on a react app using the PERN stack. The form I'm working on includes multiple date inputs, with two date columns and a total days column. My goal ...

Tips for linking together AJAX requests with vanilla JavaScript

I have searched extensively for solutions using only plain JavaScript, but I have not been able to find a suitable answer. How can I tackle this issue with pure JavaScript given that my repetitive attempts haven't yielded any results? function ...

Is the ID Column in the Minimal Material Table Demo not appearing as expected?

Hey there, I'm in the process of developing a simple demonstration of a material table - Take note that this is a stackblitz link and for some reason, the id column isn't showing up. Here's a snippet from my app.component.ts: import { C ...

Learn how to incorporate conditions into your mapping function in React to retrieve a single result

Hello everyone, I have a task where I need to compare two collections. If the comparison returns true, I want to display solved, otherwise I want to display Available. First collection : (5) [{…}, {…}, {…}, {…}, {…}] 0: creatorUserI ...

Is it possible to display this code through printing rather than using an onclick event?

I have a puzzle website in the works where users select a puzzle to solve. I am looking for a way to display the puzzles directly on the website instead of using pop-up boxes. I am proficient in various coding languages, so any solution will work for me. ...

Exploring the GitHub Repository API with React

I am currently developing a feature that allows users to enter a username and view all the github repositories for that user in a separate react component within a repolist component. Although I can retrieve the JSON data for all the repos, I am facing is ...