All Projects → sbertix → Swiftagram

sbertix / Swiftagram

Licence: apache-2.0
A modern Swift wrapper for Instagram Private API.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftagram

Instagram Web Api
🤳 Instagram Private Web API client for Node
Stars: ✭ 694 (+594%)
Mutual labels:  api, upload, instagram, client
Swiftyinsta
Instagram Private API Swift
Stars: ✭ 165 (+65%)
Mutual labels:  api, instagram-api, instagram, client
Instapy Cli
✨ Python library and CLI to upload photo and video on Instagram. W/o a phone!
Stars: ✭ 498 (+398%)
Mutual labels:  api, instagram-api, upload, instagram
Uploadcare Php
PHP API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
Stars: ✭ 77 (-23%)
Mutual labels:  api, upload, client
Instagram Api Python
Unofficial instagram API, give you access to ALL instagram features (like, follow, upload photo and video and etc)! Write on python.
Stars: ✭ 2,357 (+2257%)
Mutual labels:  api, instagram-api, instagram
Swiftinstagram
Instagram API client written in Swift
Stars: ✭ 570 (+470%)
Mutual labels:  api, instagram-api, instagram
Goinsta
Unofficial Instagram API written in Golang
Stars: ✭ 733 (+633%)
Mutual labels:  api, instagram-api, instagram
Fredr
An R client for the Federal Reserve Economic Data (FRED) API
Stars: ✭ 61 (-39%)
Mutual labels:  api, client
Igdb
Go client for the Internet Game Database API
Stars: ✭ 65 (-35%)
Mutual labels:  api, client
Instatrack
Convert Instagram user ID to username & vice versa
Stars: ✭ 70 (-30%)
Mutual labels:  api, instagram
Igql
Unofficial Instagram GraphQL API to collet data without authentication
Stars: ✭ 80 (-20%)
Mutual labels:  instagram-api, instagram
Adrestia
APIs & SDK for interacting with Cardano.
Stars: ✭ 56 (-44%)
Mutual labels:  api, client
Dsc Mercado Livre
Biblioteca de integração com o Mercado Livre
Stars: ✭ 55 (-45%)
Mutual labels:  api, client
Dimscord
A Discord Bot & REST Library for Nim.
Stars: ✭ 67 (-33%)
Mutual labels:  api, client
Instauto
Simple to use wrapper around the private Instagram API, written in Python.
Stars: ✭ 52 (-48%)
Mutual labels:  instagram-api, instagram
Sechub
SecHub - one central and easy way to use different security tools with one API/Client
Stars: ✭ 52 (-48%)
Mutual labels:  api, client
Cups Ipp
CUPS Implementation of IPP - PHP Client API
Stars: ✭ 70 (-30%)
Mutual labels:  api, client
Zhihu Oauth
尝试解析出知乎官方未开放的 OAuth2 接口,并提供优雅的使用方式,作为 zhihu-py3 项目的替代者,目前还在实验阶段
Stars: ✭ 1,237 (+1137%)
Mutual labels:  api, client
Python Nomad
Client library Hashicorp Nomad
Stars: ✭ 90 (-10%)
Mutual labels:  api, client
Pervertgram
A project for stalking people on Instagram.
Stars: ✭ 88 (-12%)
Mutual labels:  api, instagram

Header

Swift codecov Telegram
iOS macOS tvOS watchOS


Swiftagram is a wrapper for Instagram Private API, written entirely in (modern) Swift.

Instagram's official APIs, both the Instagram Basic Display API and the Instagram Graph API — available for Creator and Business accounts alone, either lack support for the most mundane of features or limit their availability to a not large enough subset of profiles.

In order to bypass these limitations, Swiftagram relies on the API used internally by the Android and iOS official Instagram apps, requiring no API token, and allowing to reproduce virtually any action a user can take. Please just bear in mind, as they're not authorized for external use, you're using them at your own risk.


What's SwiftagramCrypto?

Relying on encryption usually requires specific disclosure, e.g. on submission to the App Store.

Despite Swiftagram, as all libraries relying on unathorized third-party APIs, cannot be considered App Store safe, we still value separating everything depending on encryption into its owen target library, we call SwiftagramCrypto. Keep in mind features like BasicAuthenticator, a non-visual Authenticator, or KeychainStorage, the safe and preferred way to store Secrets, or even the ability to post on your feed and upload stories are SwiftagramCrypto only.

Please check out the docs to find out more.

Status

push GitHub release (latest by date)

You can find all changelogs directly under every release, and if you care to be notified about future ones, don't forget to subscribe to our Telegram channel.

What's next?

Milestones, issues, as well as the WIP dashboard, are the best way to keep updated with active developement.

Feel free to contribute by sending a pull request. Just remember to refer to our guidelines and Code of Conduct beforehand.

Installation

Swift Package Manager (Xcode 11 and above)

  1. Select File/Swift Packages/Add Package Dependency… from the menu.
  2. Paste https://github.com/sbertix/Swiftagram.git.
  3. Follow the steps.
  4. Add SwiftagramCrypto together with Swiftagram for the full experience.

Why not CocoaPods, or Carthage, or blank?

Supporting multiple dependency managers makes maintaining a library exponentially more complicated and time consuming.
Furthermore, with the integration of the Swift Package Manager in Xcode 11 and greater, we expect the need for alternative solutions to fade quickly.

Targets

  • Swiftagram depends on ComposableRequest, an HTTP client originally integrated in Swiftagram., and it's the core library.
    It supports Combine Publishers out of the box.

  • SwiftagramCrypto, depending on ComposableRequestCrypto and a fork of SwCrypt, can be imported together with Swiftagram to extend its functionality, accessing the safer KeychainStorage and encrypted Endpoints (e.g. Endpoint.Friendship.follow, Endpoint.Friendship.unfollow).

Usage

Check out our Examples or visit the (auto-generated) Documentation to learn about use cases.

Authentication

Authentication is provided through conformance to the Authenticator protocol, which, on success, returns a Secret containing all the cookies needed to sign an Endpoint's request.

The library comes with two concrete implementations.

WebViewAuthenticator

WebViewAuthenticator is a visual based Authenticator, relying on a WKWebView in order to log in the user. As it's based on WebKit, it's only available for iOS 11 (and above) and macOS 10.13 (and above).

Example

import UIKit
import WebKit

import ComposableRequest
import ComposableRequestCrypto
import Swiftagram

/// A `class` defining a `UIViewController` displaying a `WKWebView` used for authentication.
final class LoginViewController: UIViewController {
    /// Any `ComposableRequest.Storage` used to cache `Secret`s.
    /// We're using `KeychainStorage` as it's the safest option.
    let storage = KeychainStorage()
    /// A valid `Client`. We're relying on the `default` one.
    let client = Client.default

    /// The web view.
    var webView: WKWebView? {
        didSet {
            oldValue?.removeFromSuperview() // Just in case.
            guard let webView = webView else { return }
            webView.frame = view.bounds     // Fill the parent view.
            // You should also deal with layout constraints or similar here…
            view.addSubview(webView)        // Add it to the parent view.
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Authenticate using any `Storage` you want (`KeychainStorage` is used as an example).
        // `storage` can be omitted if you don't require `Secret`s caching.
        // `client` can be omitted and the default once will be used.
        WebViewAuthenticator(storage: storage,
                             client: client) { self.webView = $0 }
            .authenticate {
                switch $0 {
                    case .failure(let error): print(error.localizedDescription)
                    default: print("Login succesful.")
                }
            }
        }
    }
}

BasicAuthenticator

BasicAuthenticator is a code based Authenticator, supporting 2FA, defined in SwiftagramCrypto: all you need is a username and password and you're ready to go.

Example

import ComposableRequest
import ComposableRequestCrypto
import Swiftagram
import SwiftagramCrypto

/// Any `ComposableRequest.Storage` used to cache `Secret`s.
/// We're using `KeychainStorage` as it's the safest option.
let storage = KeychainStorage()
/// A valid `Client`. We're relying on the `default` one.
let client = Client.default

/// Authenticate.
BasicAuthenticator(storage: storage,    // Optional. No storage will be used if omitted.
                   client: client,      // Optional. Default client will be used if omitted.
                   username: /* username */,
                   password: /* password */)
    .authenticate {
        switch $0 {
        case .failure(let error):
            // Please check out the docs to find out how to deal with 2FA.
            print(error.localizedDescription)
        default: print("Login successful.")
        }
    }

Caching

Caching of Secrets is provided through conformance to the Storage protocol in ComposableRequest.

The library comes with several concrete implementations.

  • TransientStorage should be used when no caching is necessary, and it's what Authenticators default to when no Storage is provided.
  • UserDefaultsStorage allows for faster, out-of-the-box, testing, although it's not recommended for production as private cookies are not encrypted.
  • KeychainStorage, part of ComposableRequestCrypto, (preferred) stores them safely in the user's keychain.

Request

How can I bypass Instagram "spam" filter, and make them believe I'm not actually a bot?

Just set the default waiting time in the Requester to something greater than 0.

import ComposableRequest
import Swiftagram
import SwiftagramCrypto

// Somewhere in your code, for instance in your `AppDelegate`, set a new `default` `Requester`.
// `O.5` to `1.5` seconds is a long enough time, usually.
// `Requester.instagram` deals about it for you.
Requester.default = .instagram

Or just create a custom Requester and pass it to every single request you make.

What if I wanna know the basic info about a profile?

All you need is the user identifier and a valid Secret.

let identifier: String = /* the profile identifier */
let secret: Secret = /* the authentication response */

// Perform the request.
Endpoint.User.summary(for: identifier)
    .unlocking(with: secret)
    .task {
        // Do something here.
    })
    .resume() // Strongly referenced by default, no need to worry about it.

What about cancelling an ongoing request?

Easy!

let secret: Secret = /* the authentication response */

// Perform the request.
let task = Endpoint.Friendship.following(secret.id)
    .unlocking(with: secret)
    .task(maxLength: 10,
          onComplete: { _ in },
          onChange: { _ in  
            // Do something here.
    })
    .resume() // Exhaust 10 pages of followers.

// Cancel it.
task?.cancel()

What about loading the next page?

Just resume it once more. If it's still fetching, nothing's gonna happen. But if it's not and there are still more pages to be fetched, a new one will be requested.

Special thanks

Massive thanks to anyone contributing to TheM4hd1/SwiftyInsta, dilame/instagram-private-api and ping/instagram_private_api, for the inspiration and the invaluable service to the open source community, without which there would likely be no Swiftagram today.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].