fulhamHead
fulhamHead

Reputation: 687

Generate access token Instagram API, without having to log in?

So I am building a restaurant app and one of the features I want is to allow a user of the app to see photos from a particular restaurant's Instagram account. And I want a user to be able to see this without having to login to their Instagram account, so they shouldn't even need an Instagram account for this to work.

So I have read this answer How can I get a user's media from Instagram without authenticating as a user?

And I tried what it said and used the client_id(which I recieved when I registered my app using my personal Instagram account), but I still get an error back saying :

{
    meta: {
          error_type: "OAuthAccessTokenException",
          code: 400,
          error_message: "The access_token provided is invalid."
     }
}

The endpoint I am trying to hit is :

https://api.instagram.com/v1/users/search?q=[USERNAME]&client_id=[CLIENT ID]

So do I absolutely need an access token for this to work(and thus have to enforce a user to log in) ?

If I do, then is there way to generate an access token somehow without forcing the user log in?

I believe there is a way around this, as the popular dating app Tinder has this desired functionality I am looking for, as it allows you to see photos from people's Instagram account without having to log in! (I have just verified this 5 minutes ago!)

Any help on this would be much appreciated.

Thanks.

Upvotes: 4

Views: 7434

Answers (3)

rgdigi
rgdigi

Reputation: 1747

Since the endpoints don't exist anymore I switched to a PHP library - https://github.com/pgrimaud/instagram-user-feed

Installed this lib with composer:

composer require pgrimaud/instagram-user-feed "^4.0"

To get a feed object -

$cache = new Instagram\Storage\CacheManager();
$api   = new Instagram\Api($cache);
$api->setUserName('myvetbox');
$feed = $api->getFeed();

Example of how to use that object -

foreach ($feed->medias as $key => $value) {
   echo '<li><a href="'.$value->link.'" target="_blank"><img src="'.$value->thumbnailSrc.'"></a></li>';
}

Upvotes: 1

altinturk
altinturk

Reputation: 147

Edit April 2018: After facebook privacy case this endpoint is immediately put out of service. It seems we need to parse the JSON embedded in <script> tag directly within the profile page:

<script type="text/javascript">window._sharedData = {"activity_counts":...

Any better ideas are welcome.


You can use the most recent link

GET https://www.instagram.com/{username}/?__a=1

to get latest 20 posts in JSON format. Hope you put this to good use.


edit: other ways aren't valid anymore: https://www.instagram.com/{username}/media/

Upvotes: 5

krisrak
krisrak

Reputation: 12952

Instagram used to allow most API requests with just client_id and without access_token, the apps registered back in the day still work with way, thats how some apps are able to show instagram photos without user login. Instagram has changes the API specification, so new apps will have to get access_token, older apps will have to change before June 2016.

One way you can work around this is by using access_token generated by your account to access photos. Login locally and get access_token, use this for all API calls, it should not change, unless u change password,if it expires, regenerate and update in your server.

Upvotes: 1

Related Questions