# SwiftyInsta | Instagram Unofficial Private API Swift

**URL:** <https://onehack.st/t/swiftyinsta-instagram-unofficial-private-api-swift/162151>\
**Category:** Tools & Scripts\
**Tags:** tools, programming, social-media\
**Created:** [November 11, 2020, 12:21pm UTC](https://onehack.st/t/swiftyinsta-instagram-unofficial-private-api-swift/162151 "2020-11-11T12:21:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PlayBoy83](https://onehack.st/user_avatar/onehack.st/playboy83/32/164314_2.png) [@PlayBoy83](https://onehack.st/u/PlayBoy83)\
**Post date:** [November 11, 2020, 12:21pm UTC](https://onehack.st/t/swiftyinsta-instagram-unofficial-private-api-swift/162151/1 "2020-11-11T12:21:41Z")

</div>

![image](https://onehack.st/uploads/default/original/3X/5/b/5b8ac296d5c19b1d23828add1f0635f2b00b7903.jpeg)

**Instagram** offers two kinds of APIs to developers. The [Instagram API Platform](https://www.instagram.com/developer/) (extremely limited in functionality and close to being discontinued), and the [Instagram Graph API](https://developers.facebook.com/docs/instagram-api) for _Business_ and _Creator_ accounts only.

However, **Instagram** apps rely on a third type of _API_, the so-called **Private API** or _Unofficial API_, and [SwiftyInsta](https://github.com/TheM4hd1/SwiftyInsta) is an **iOS, macOS, tvOS and watchOS client** for them, written entirely in **Swift**. You can try and create a better Instagram experience for your users, or write bots for automating different tasks.

These _Private API_ require no _token_ or _app registration_ but they’re not _authorized_ by Instagram for external use. Use this at your own risk.

**Installation**

**Swift Package Manager (Xcode 11 and above)**

1. Select `File`/`Swift Packages`/`Add Package Dependency…` from the menu.
2. Paste `https://github.com/TheM4hd1/SwiftyInsta.git`.
3. Follow the steps.

**CocoaPods**

[CocoaPods](https://cocoapods.org/) is a dependency manager for Cocoa projects. You can install it with the following command:

```auto
$ gem install cocoapods  

```

To integrate **SwiftyInsta** into your Xcode project using CocoaPods, specify it in your `Podfile`:

```auto
use_frameworks! target '<Your Target Name>' do pod 'SwiftyInsta', '~> 2.0' end  

```

Then, run the following command:

```auto
$ pod install  

```

**SwiftyInsta** depends on [CryptoSwift](https://github.com/krzyzanowskim/CryptoSwift) and [keychain-swift](https://github.com/evgenyneu/keychain-swift).

**Login**

**`Credentials`**

```auto
$ gem install cocoapods

```

Once the user has typed the two factor authentication code or challenge code, you simply do

```auto
use_frameworks!target '<Your Target Name>' do pod 'SwiftyInsta', '~> 2.0'end

```

And the `completionHandler` in the previous `authenticate(with: completionHandler:)` will automatically catch the response.

**`LoginWebViewController` (\>= iOS 12 only)**

```auto
$ pod install

```

Or implement your own custom `UIViewController` using `LoginWebView`, and pass it to an `APIHandler` `authenticate` method using `.webView(/* your login web view */)`.

**`Authentication.Response`**

If you’ve already persisted a user’s `Authentication.Response`:

```auto
// these need to be strong references.self.credentials = Credentials(username: /* username */, password: /* password */, verifyBy: .text)self.handler = APIHandler()handler.authenticate(with: .user(credentials)) { switch $0 { case .success(let response, _): print("Login successful.") // persist cache safely in the keychain for logging in again in the future. guard let key = response.persist() else { return print("`Authentication.Response` could not be persisted.") } // store the `key` wherever you want, so you can access the `Authentication.Response` later. // `UserDefaults` is just an example. UserDefaults.standard.set(key, forKey: "current.account") UserDefaults.standard.synchronize() case .failure(let error): if error.requiresInstagramCode { /* update interface to ask for code */ } else { /* notify the user */ } }}

```

**Usage**

All endpoints are easily accessible from your `APIHandler` instance.

```auto
self.credentials.code = /* the code */

```

Futhermore, responses now display every single value contained in the `JSON` file returned by the **API** : just access any `ParsedResponse` `rawResponse` and start browsing, or stick with the suggested accessories (e.g. `User`‘s `username`, `name`, etc. and `Media`‘s `aspectRatio`, `takenAt`, `content`, etc.).

## GitHub:

> **[GitHub - TheM4hd1/SwiftyInsta: Instagram Private API Swift](https://github.com/TheM4hd1/SwiftyInsta)**
>
> Instagram Private API Swift
