Search code examples
iosswiftoauth-2.0instagram-api

OAuth background login from swift app


I'm building an app (iOS, Swift), that has to fetch images from multiple instagram users. So I've registeret myself as instagram developer, and my app as a client app. The users of the app won't have to login to instagram, just the app from the background.

I'm confused about how to do this. I have tried with OAuthSwift library, but when I follow the example, it transfers my to safari with a webview, in which the user has to login.

Shouldn't it be fairly easy to log the client app in from the background? something like call instagram authentication url with the client key and secret, and receive an access token when authenticated?

I havn't been able to find some good simple examples about this! Maybe someone can give some clues to what direction I should go in?

I'm new to OAuth, maybe I've misunderstood something.


Solution

  • Okay, so I have been researching this for a while now.. And it seems that apps submittet before 17. Nov. 2015, could use client_id to fetch images from the instagram API. However, since the API-updates, it is now no longer possible to do that, all calls to the API needs to have the access_token. It seems that there are no way to get an access_token from instagram from the background of an app.

    Another way to just watch the images from any instagram user without user authentication, is to directly fetch the media-items like this:

    https://www.instagram.com/[instagram-user]/media/

    where [instagram-user] should be replaced by the instagram username or user id from a specifik instagram user.

    This will return the 20 most recent media items that user has posted in json format. For loading more media items, a query can be used: ?max_id=

    https://www.instagram.com/[instagram-user]/media/?max_id=[max_id]

    where [max_id] should be replaced by the maximum id of the media image that should be returned. Also [min_id] can be used.

    However! I can't find anything about this approach in the documentation. So I don't know anything about the rate limits, platform guidelines or whether this method will be disabled in June when the old API deprecated. If anyone has documentation on this method, please share!