Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eriktobben's avatar

Access to Instagram API

Hi!

I am trying to authenticate to the Instagram API, and I have some questions I hope someone can answer:

I am using the API to fetch images from a certain area, but as far as I can see from the docs, there is only documentation for authenticating -users-. I only need to authenticate my application. Can I authenticate with my personal Instagram user, and save the token as a variable in Laravel? (In the docs it states that the token can be changed, how do I handle this?).

It seems that the documentation is focused on applications where you authenticate your users so that you can access their information, but I only need to consume general data.

0 likes
6 replies
d3xt3r's avatar

Not very clear, try reframing the question with some use case and better some codes that you already tried.

eriktobben's avatar

Sorry if I wasn't clear. I am having trouble understanding how to authenticate in the Instagram API.

In the documentation: https://www.instagram.com/developer/authentication/ as I understand it, the docs is describing the way to authenticate a user. What I need is to authenticate my application so I can consume the API. Like in Mailgun or Stripe where I get a secret and a public key that authenticates my application, and I can use these credentials to fetch data.

From the Instagram docs: "Direct the user to our authorization url. If the user is not logged in, they will be asked to log in. The user will be asked if they would like to grant your application access to her Instagram data."

I do not want to redirect the user to authorize access via my application, I simply want to fetch images from a certain geo-location. So when a user is visiting my site, the images are displayed, without the need for the user to log in to Instagram and grant my application access.

d3xt3r's avatar

I what you are trying to fetch belongs to a user, you will need user to authorise it. I don't think any social network ( for reasons including me suing them) will authorise an external application to fetch content without user permission.

eriktobben's avatar

Yes, I get that. I'm not trying to get -your- images if they are private, just the images that are available on a public profile. When I test and authenticate with my personal profile, I can fetch images that is not mine or one of my friends if I search by hashtag or location. As long as the profile is public of course.

Problem is, the access_token I get when authenticating with my personal user, can change in the future (Access tokens may expire at any time in the future.), and I can't keep reauthenticate when that happens.

d3xt3r's avatar

I'm not trying to get -your- images if they are private, just the images that are available on a public profile. When I test and authenticate with my personal profile, I can fetch images that is not mine or one of my friends if I search by hashtag or location. As long as the profile is public of course.

In oauth world, we consider this as client credentials grant, where the client has access to certain resources (like the public content). I am not sure if Instagram allows that, if it does, you won't need the user to authorise your application.

Problem is, the access_token I get when authenticating with my personal user, can change in the future (Access tokens may expire at any time in the future.), and I can't keep reauthenticate when that happens.

Yes, we you will have to deal with that. Usually, Oauth providers provide refresh tokens for getting a fresh access token once it has expired, without (re) involving the user. Check their documentation, if that's supported. If they don't, you will have the user re-authorise you (no escape there)

Please or to participate in this conversation.