Giter Site home page Giter Site logo

andergoig / swiftinstagram Goto Github PK

View Code? Open in Web Editor NEW
578.0 19.0 81.0 3.55 MB

Instagram API client written in Swift

Home Page: https://git.io/vdNAn

License: MIT License

Swift 96.16% Objective-C 0.75% Ruby 3.10%
ios swift swift-library instagram instagram-client instagram-api instagram-lib xcode cocoapods carthage instagram-sdk swift-framework social authentication token-authetication sdk api

swiftinstagram's Introduction

SwiftInstagram Logo

Platforms Swift 4.0 Travis Codebeat Documentation License

CocoaPods compatible Carthage compatible Swift Package Manager


SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Features

  • Effortless and straightforward use.
  • Up-to-date with the latest Instagram API features.
  • Secure access token storing, thanks to keychain-swift.
  • Client-Side authentication.
  • 100% documented code.
  • Use of Swift 4 Decodable.
  • Up-to-date with the latest Apple technologies (Swift 4, Xcode 9, etc).

Requirements

  • iOS 9.0+
  • Xcode 9.0+

Usage

I've prepared a wiki page where you can find tons of useful things.

Contributing

If you have feature requests or bug reports, feel free to help out by sending pull requests or by creating new issues. Please take a moment to review the CONTRIBUTING guidelines.

Credits

SwiftInstagram is brought to you by Ander Goig and contributors to the project. If you're using SwiftInstagram in your project, attribution would be very appreciated.

Companion libraries

SwiftInstagram uses keychain-swift by @evgenyneu to safely store the access token retrieved by the authentication process.

License

SwiftInstagram is released under the MIT license. See LICENSE for details.

Author

Ander Goig, [email protected]

https://github.com/AnderGoig/SwiftInstagram

swiftinstagram's People

Contributors

andergoig avatar josecalles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftinstagram's Issues

Unable to make requests

Checklist

Expected Behavior

Being able to make any request after login. Can't initialize data in request() -> urlSession.dataTask

Actual Behavior

Error when invoking api.userFollows(...):
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Error when invoking getInstagramData()=api.user(...):
decoding(message: "The data couldn’t be read because it is missing.") The operation couldn’t be completed. (SwiftInstagram.InstagramError error 0.)

Steps to Reproduce the Problem

  1. Login button action

`
static func loginInstagram(from: UINavigationController, completion: @escaping (Error?) -> Void){
let api = Instagram.shared

    // Login
    //print("Instragam Login")
    api.login(from: from, withScopes: [.basic, .publicContent], success: {
        completion(nil)
    }, failure: { error in
        print(error.localizedDescription)
    })

}
`
2. Get data button action

`
static func getInstagramData() {
let api = Instagram.shared

    api.user("self", success: { userList in
        print(SwiftyJSON.JSON(userList))
    }, failure: { error in
        print(error)
        print(error.localizedDescription)
    })

}
`

However this works:
Alamofire.request("https://api.instagram.com/v1/users/self?access_token="+api.retrieveAccessToken()!).responseJSON(completionHandler: { response in if let result = response.result.value { let swiftyJSON = JSON(result) print(swiftyJSON) }

Specifications

  • iOS Version:latest
  • Device(s):all iOS devices

Example Project does not log in successfully

Checklist

Expected Behavior

Clicking the login button, the example project logs in

Actual Behavior

After entering all my data into instagram, the view controller returned with an error message

Steps to Reproduce the Problem

  1. Run example app InstagramLogin-Example
  2. Try to log in

Specifications

  • iOS Version:
    iOS 11.4
  • Device(s):
    Simulator - iPhone 6s

image

compile error: success and failure are inaccessible due to 'private' protection level

Checklist

Expected Behavior

There should be no compile errors.

Actual Behavior

Compile errors in InstagramLoginViewController:
'success' is inaccessible due to 'private' protection level
'failure' is inaccessible due to 'private' protection level

Steps to Reproduce the Problem

  1. pod install 'SwiftInstagram', '~> 1.0.5'
  2. build project
  3. there are compile errors mentioned above.

Specifications

  • xCode Version: Version 9.0.1 (9A1004)
  • macOS Version: Sierra 10.12.6 (16G29)
  • iOS Version: Generic iOS Device
  • Device(s):

error 3 bad request error.

Checklist

Expected Behavior

authentication

Actual Behavior

bad request error 3 with authentication

Steps to Reproduce the Problem

1.I will use client side only there is no backend.
2.What should I wrote instagram API's redirect url? Because there is no website or backend.
3.I wrote incorrect url because of this.

Specifications

  • iOS Version:11.4
  • Device(s):6s

mediaList property gives only string instead of array value

Checklist

Expected Behavior

I'm expecting to get URL array instead of one string value. In recentMedia(fromUser:success:failure:) method

Actual Behavior

It's gives only one string value it contains 20 recent media URLs

Steps to Reproduce the Problem

  1. Authenticate
  2. Call recentMedia(fromUser:success:failure:) method
  3. In success block API gives [InstagramMedia] and its images property is not array value.

Example Project

I think it would be nice if an example project can be provided. Just a demo

Instagram authentication not working properly

Checklist

Expected Behavior

When I am prompted the instagram login screen, and I push 'Log in', the success or failure callback should be triggered.

Actual Behavior

When I am prompted the instagram login screen, and i push 'Log in', I am routed to a Instagram branded, 'page not found' page. None of the callbacks are called and I don't receive an access token.

I inspected the traffic and it looks like the following POST call is resulting in a 404, regardless whether the username or password is correct:
https://www.instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize%3Fclient_id%CLIENT_ID%26redirect_uri%3DREDIRECT_URI%26response_type%3Dtoken%26scope%3Dbasic

I think the issue may be around this.

Steps to Reproduce the Problem

  1. Ensure user is logged out. Just call this method to bring up the instagram login screen.
Instagram.shared.login(from: self.navigationController!, success: {
                    print("Success")
                }, failure: { error in
                    print(error.localizedDescription)
                })

Specifications

  • iOS Version: 11.2
  • Device(s): iPhone 7

JSON parser breaks when parsing ids of locations within photo tags

(lldb) po error
▿ DecodingError
  ▿ dataCorrupted : Context
    ▿ codingPath : 4 elements
      - 0 : CodingKeys(stringValue: "data", intValue: nil)
      ▿ 1 : _JSONKey(stringValue: "Index 4", intValue: 4)
        - stringValue : "Index 4"
        ▿ intValue : Optional<Int>
          - some : 4
      - 2 : CodingKeys(stringValue: "location", intValue: nil)
      - 3 : CodingKeys(stringValue: "id", intValue: nil)
    - debugDescription : "Parsed JSON number <531383683876521> does not fit in Int."
    - underlyingError : nil

Instagram sends strings for ids for pretty much everything, but it seems it sends ints for locations. Huge ints at that. They don't fit in 64 bits and the swift parser doesn't like that at all.

Edited/censored offending JSON. The data within the location node hasn't been altered:

{
	"pagination": {
		"next_max_id": "censored",
		"next_url": "censored"
	},
	"data": [{
		"id": "123123123_123123123",
		"user": {
			"id": "12345678",
			"full_name": "Censored",
			"profile_picture": "censored",
			"username": "censored"
		},
		"images": {
			"thumbnail": {
				"width": 150,
				"height": 150,
				"url": "censored"
			},
			"low_resolution": {
				"width": 320,
				"height": 320,
				"url": "censored"
			},
			"standard_resolution": {
				"width": 640,
				"height": 640,
				"url": "censored"
			}
		},
		"created_time": "1515524886",
		"caption": {
			"id": "12345678",
			"text": "censored",
			"created_time": "1515524886",
			"from": {
				"id": "1297516609",
				"full_name": "Censored",
				"profile_picture": "censored",
				"username": "censored"
			}
		},
		"user_has_liked": false,
		"likes": {
			"count": 17
		},
		"tags": [],
		"filter": "Normal",
		"comments": {
			"count": 0
		},
		"type": "image",
		"link": "censored",
		"location": {
			"latitude": -22.951586524616,
			"longitude": -43.210792243481,
			"name": "Cristo Redentor Rio de Janeiro",
			"id": 531383683876521
		},
		"attribution": null,
		"users_in_photo": []
	}],
	"meta": {
		"code": 200
	}
}

Error 1 when trying to receive Instagram followers

Checklist

Expected Behavior

Retrieve followers

Actual Behavior

Receiving an error: "The operation couldn’t be completed. (SwiftInstagram.InstagramError error 1.)"

Steps to Reproduce the Problem

  1. Performing the api.login
  2. Login was successful
  3. Calling the "api.userFollowers" function, which fails immediately.

I think I know the why I get this error but I want to make sure I'm not wrong:
I have my client ID and all that, but the permissions has not been reviewed yet.
Also, Instagram says that the use case of "my app is still in development" is not valid and you should only ask when going to production (which is weird, how can I test the data and all that??)

So overall:

  1. Do you think the issue is related to the lack of permissions?
  2. If so, can you help advise on how to get permissions without having a website or privacy policy?

Thank you!

Specifications

  • iOS Version: 11.3.1
  • Device(s): iPhone X

api.like error "retired"

When I Use api.like service, I get this error "This endpoint has been retired". Media Id is true also.

Authentication fails

Checklist

Expected Behavior

Authentication should succeed

Actual Behavior

Authentication fails after challenge

Steps to Reproduce the Problem

  1. execute the api.login(...) method
  2. type in username and password in the presented webView
  3. an "Unusual login attempt" warning is prompted and email/SMS verification is required
  4. perform authentication
  5. access_token is not fetched

Specifications

  • iOS Version: 11.3
  • Device(s): iOS simulator

screen shot 2018-04-07 at 5 39 16 pm

Error 1- "This endpoint has been retired" error?

Checklist

Expected Behavior

retrieve follower list data

Actual Behavior

retrieving Error 1- "This endpoint has been retired" error

Steps to Reproduce the Problem

1.When retrieving the followerlist data this gave me response gave me this error.
2. I think instagram change endpoints so this framework should be update.

Specifications

  • iOS Version:
  • Device(s):

End point retired

Checklist

  • I've the latest update of SwiftInstagram.
    I currently start with this library, and I found out that the search Instagram user endpoint is not working

basically, I try to call the end-point search user and the error said "this endpoint has been retired"
is there any other solution to retrieve user info?

Expected Behavior

Actual Behavior

return error "this endpoint has been retired"

Steps to Reproduce the Problem

just call the end point api.search(user query: String, count: Int? = nil, success: SuccessHandler<[InstagramUser]>?, failure: FailureHandler?)

Specifications

  • iOS Version: 9
  • Device(s):

Cocoapods bug

Hello, I can't install the library with cocoa pods:

pod install
Analyzing dependencies
[!] Unable to find a specification for `SwiftInstagram (~> 1.0.4)`

Add pagination support

Add support for Instagram JSON pagination. Currently, the next_url parameter decoded from the Instagram responses is not used in any way.

authentication not working

let igLoginManager = Instagram.shared
igLoginManager.login(from: vc, success: {
// not callback (success)
}) { (error) in
// not callback (error)
}

I do not get any answers.
Disable implicit OAuth: uncheck
InstagramClientId: my details
InstagramRedirectURI: my details

I get successfully to my page and do not get any response. Please tell me what could be wrong

Remember user

A feature to remember the user so they do not have to sign in every time would be very useful :)

Cannot login

Checklist

Expected Behavior

Should login succesfully.

Actual Behavior

Not login succesfully. Received an Error in webview.
screen shot 2018-05-25 at 17 54 11 (see attached screenshot)

Steps to Reproduce the Problem

  1. Added pod to Podfile and install
  2. Added to Info.plist keys from 'SwiftInstagram authentication' section
  3. Added sample code for login

Specifications

  • iOS Version: 11.0
  • Device(s): Simulator / iPhone 6

pod 'SwiftInstagram', '~> 1.1.0' not working

When I run a pod install, I get the following error:

[!] Unable to satisfy the following requirements:

  • SwiftInstagram (~> 1.1.0) required by Podfile

None of your spec sources contain a spec satisfying the dependency: SwiftInstagram (~> 1.1.0).

You have either:

  • out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

PS: I have many other pods that were successfully able to install, this is the only one that I am having trouble with.

SwiftInstagram.InstagramError error 0

As of today, I keep getting this error message when I call recentMedia(fromUser: "self"....
This error was non-existent up until today. Here's what gets printed in the console:

The operation couldn’t be completed. (SwiftInstagram.InstagramError error 0.)

I am still able to login and logout. This error only occurs when I call api.recentMedia(fromUser: "self"....

Another thing to note is that when I enter this link in my web browser "https://api.instagram.com/v1/users/self/media/recent?access_token=MYTOKEN", I am able to get a response from Instagram, which proves it is not a problem on Instagrams end. It is possible that they have slightly changed the response as of today, which might be causing problems with this api, but I am not too sure about that.

UPDATE: After digging in further, I have located where the error occurs. Still not sure why it throws an error. After running line 139 (refer to the image below), the app then catches an error and then runs line 156. Please help me fix this problem, thanks!

screen shot 2018-04-06 at 1 18 31 am

Change key for keychain

Can the key be changed from "accessToken" to something unique so that it won't interfere with other uses? I would suggest "andergoig_swiftinstagram_accesstoken".

Getting nil while calling the login method.

Checklist

Expected Behavior

  1. Should not crash at the starting only when calling the login method.

Actual Behavior

  1. Getting crash on calling this - api.login(from: navigationController!, success: {
    // Do your stuff here ...
    }, failure: { error in
    print(error.localizedDescription)
    })
    Error - Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

Steps to Reproduce the Problem

  1. Just call this :- let api = Instagram.shared

    // Login
    api.login(from: navigationController!, success: {
    // Do your stuff here ...
    }, failure: { error in
    print(error.localizedDescription)
    })

Specifications

  • iOS Version: 11.3
  • Device(s): iPhone6+

Invalid Media ID

Checklist

Expected Behavior

I should get Media data as Instagram Documentation like this Instagram media

Actual Behavior

I have already Authentication then get media data
Auth -> Fetch Data (Media)
but i got an error like this
[invalidRequest] - invalid media id

Steps to Reproduce the Problem

  1. Auth
  2. Fetch with this shortcode Ba6NSWUFLfj

Specifications

  • iOS Version: iOS 100
  • Device(s): Simulator iPhone 8 Plus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.