AnderGoig / SwiftInstagram

Instagram API client written in Swift
https://git.io/vdNAn
MIT License
578 stars 81 forks source link

InstagramLocation #7

Closed Dzionis closed 6 years ago

Dzionis commented 6 years ago

Property 'id' should be Int in the 'InstagramLocation' model 2017-10-12 16 37 11

AnderGoig commented 6 years ago

Hey @Dzionis thanks for your help and your pull request (#8), unfortunately, I'm not sure thats correct. In fact, I have tested it and this was the Instagram API response:

{
    "data": {
        "id": "213135265",
        "name": "Minsk-Arena", 
        "latitude": 53.9365, 
        "longitude": 27.4829
    }, 
    "meta": { 
        "code": 200
    }
}

You can see the id is a String and I haven't had any parse issue, how have you tested it, or where did you find that?

Thanks! :thumbsup:

Dzionis commented 6 years ago

Thank you for quick reply @AnderGoig . I logged in by this code:

api.login(navController: navigationController!, scopes: [.basic, .likes, .followerList, .publicContent], success: {
                // Do your stuff here ...
            }, failure: { error in
                print(error.localizedDescription)
            })

and I got media by this code:

api.recentMedia(fromUser: "self", count: 5, success: { (mediaSet) in

        }, failure: { (error) in
            print(error.localizedDescription)
        })

And i got response: [jsonParseError] - The data couldn’t be read because it isn’t in the correct format.

AnderGoig commented 6 years ago

Oh :hushed:, I see.

It seems like the Instagram API returns a different type of id depending on the called endpoint. The location id returned from a media object is an Int, as you said. But the location id returned from a call to /locations/location-id is a String.

Unfortunately, your pull request (#8) would do the trick with the first example, but would fail with the second.

The only thing I can think of is to have an internal struct inside InstagramMedia.swift for the location property that would parse the id's as Int.

Thank you very much, I wouldn't have discovered this without your help! 👍

AnderGoig commented 6 years ago

Fixed in 7bdaa34.