0

I've been using String(contentsOfURL: NSURL) to retrieve the HTML file of a website (a post on Instagram like this one https://instagram.com/p/5FcnSATPa4/ in my case). I need some information about the post like how many likes the post has received or the location associated with the photo.

This line of the HTML file, for example, contains some of the info I need \"location\":{\"has_public_page\":true,\"name\":\"Kaputa\\u015f Beach\". The question is: how can I extract that "Kaputa Beach" name?

Thank you.

1 Answer 1

4

Why not use the actual Instagram API? https://instagram.com/developer/endpoints/likes/

Why spend time parsing the HTML when you get that information straight from the source.

You can authorise using OAuth (https://github.com/dongri/OAuthSwift)

You could retrieve a list of users who have liked an image using the call below, you can then derive the 'like' count from this:

https://api.instagram.com/v1/media/{media-id}/likes?access_token=ACCESS-TOKEN

Alternatively if you want more information on the media, you can use the following endpoint:

https://api.instagram.com/v1/media/{media-id}?access_token=ACCESS-TOKEN

Details here: https://instagram.com/developer/endpoints/media/#get_media

Here is an example of a swift app using the Instagram API, you can check out the project on GitHub to see how it works.

https://maniacdev.com/2015/01/example-a-swift-based-ios-instagram-photo-downloader-and-browser


EDIT:

You don't need to authenticate as a particular user to use the methods you need.

  1. Login to instagram as yourself: https://instagram.com/accounts/login/

  2. Register a new client: https://instagram.com/developer/clients/manage/

  3. Use your new client id with requests instead of your access token: https://api.instagram.com/v1/media/{media-id}/likes?client_id={CLIENT_ID} or https://api.instagram.com/v1/media/shortcode/5FcnSATPa4?client_id={CLIENT_ID}

You can make up to 5000 requests per hour with your client id.

You can play around with the Instagram API here: https://apigee.com/console/instagram

Just remember to use your client id.

Sign up to request clarification or add additional context in comments.

2 Comments

Of course that's a possibility. However, in order to take advantage of the Instagram API, I need the users to log in with their Instagram accounts, while, in my app, it is crucial that does not happen. That's why I need to brutally parse the HTML… For some information related to the post, I'm using these embedding features that do not require the log in instagram.com/developer/embedding but this way I just get photo's title and image file. Location, upload date and likes are not available...
See edits, you don't need to have each user login. You can register your application and use the client id to make most requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.