Lightweight and Testable Twitter library for iOS and macOS written in Swift

Lightweight and Testable Twitter library for iOS and macOS written in Swift

A Twitter library written in Swift that is lightweight, testable and easy to use.

The twitterkit is a lightweight and testable Twitter library for iOS and macOS written in Swift. It allows developers to create Twitter apps that are fast, reliable, and easy to maintain.

A lightweight and tested Twitter library built in Swift that uses Combine and async/await.

Swift

  • [x] Twitter v1 API support (OAuth1.0)
  • [x] Use Twitter to log in.
  • [x] Managing multiple accounts
  • [x] Making an approved URLRequest is supported.
  • [x] Allow for the upload of chunked material
  • [ ] Twitter v2 API support (OAuth2.0)

Make use of the swift package management.

Use Twitter to log in.

Use TwitterAuthorizationFlow, TwitterAccountStore, and ClientCredential.

  1. Get ready to log in.

Kotori / Your login credentials allow the customer to ClientCredential =.init(consumerKey: “Your consumer key from https://developer.twitter.com”, consumerSecret: “Your consumer secret from https://developer.twitter.com”) URL: URL(string: “See https://developer.twitter.com for your app’s url scheme”)!) / Manager of the login flow. Twitter is free to use. TwitterAuthorizationFlow = LoginFlow (clientCredential: clientCredential, urlSession: .shared) / Manager of accounts. accountStore = TwitterAccountStore; let accountStore = TwitterAccountStore; let accountStore = TwitterAccount (keychainAccessGroup: “Your keychain access group.”)

  1. Begin the handshake of authorization.

twitterLoginFlow.authorize() is a function that allows you to authorize yourself on Twitter. (on: RunLoop.main) receive(on: RunLoop.main) receive(on: RunLoop.main) receive( receive (sink) self.credentials = accountStore.allCredentials() / Get all logged in accounts.) Completion: in, receiveValue: credentials in accountStore.add(credential) / Save to the keychain. keep in mind (in: &cancellables)

  1. In your app, go to the Twitter login screen.

Kotori requests that you access the Twitter login page so that the user may approve you. As a result, include codes in your program that access the Twitter login screen.

For TwitterAuthorizationFlow.resourceOwnerAuthorizationOpenURL, use NotificationCenter.default.publisher. receive (sink) guard let url = output.object as? completion: in, receiveValue: output in URL else fatalError() / In SwiftUI or UIKit, provide WebView or SFSafariViewController for user authentication.) keep in mind (in: &cancellables)

  1. From the Twitter login page, launch your app. (Scheme for URLs)

After successfully logging in to Twitter, the website redirects to your app using a url scheme that includes credential parameters. As a result, include scripts that handle the url scheme and send it to Kotori.

.onOpenURL(perform: url in twitterLoginFlow.handleCallbackFromTwitter(url: url) ).onOpenURL(perform: url in twitterLoginFlow.handleCallbackFromTwitter(url: url) ).onOpenURL(perform: url in twitterLoginFlow.handleCallbackFromTwitter(url: url Use the AppDelegate function in UIKit. func application (UIApplication.OpenURLOptionsKey : Any] = [:]) ( app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) ( app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptions -> Bool twitterLoginFlow.handleCallbackFromTwitter(url: url) twitterLoginFlow.handleCallbackFromTwitter(url: url) twitterLoginFlow.handleCallbackFromTwitter(url: url)

  1. Handle the Kotori’s login completion callback.

After that, twitterLoginFlow.authorize is called (). The function sink() will be used.

Management of accounts

Use TwitterAccountStore to manage your Twitter account.

accountStore = TwitterAccountStore; let accountStore = TwitterAccountStore; let accountStore = TwitterAccount (keychainAccessGroup: “your keychain access group”) accountStore.allCredentials()

API call

Use TwitterAPIRequest to make a request on Twitter.

The network layer, response parser, is not provided by Kotori. Only URLRequest is supported.

Twitter is free to use. TwitterAPIRequest(resource) = Request Endpoint.statusUpdate is a URL that can be found at http://endpoint.statusUpdate.com/. Client: credentials, method:.POST, parameters: tweet.asParameters(), credential: credentials clientCredential))))))))))))))))))) let twitterRequest = urlRequest Request.makeURLRequest()

Use TwitterMediaUploader to upload files to Twitter.

Kotori allows for chunked uploads. Chuneked upload is a quick upload technique, however it involves a lot of stages and is tough to master. As a result, Kotori may be able to assist you.

An example of a single picture upload.

Try waiting for uploader using TwitterMediaUploader =.init(credential: credential,data: media.data, mimeType: media.mimeType, clientCredential: clientCredential, index: index) upload()

An example of several picture uploads.

[MediaUploadOutput] = [] var mediaUploadResults: Try ThrowingTaskGroup(of: MediaUploadOutput.self, body: ) to see what happens. group in tweet.medias.enumerated() for (index, media) group.addTask (priority: .userInitiated) appoint an uploader: Twitter return try await uploader.upload() for try await output in group mediaUploadResults.append(output) ) MediaUploader =.init(credential: credential, data: media.data, mimeType: media.mimeType, clientCredential: clientCredential, index: index)

PRs are encouraged. The format is completely free!

In Japanese, a kotori is a tiny bird.

Kotori is a Twitter library that is tiny and lightweight.

GitHub

https://github.com/TomoyaOnishi/Kotori

The twitter ios sdk is a lightweight and testable Twitter library written in Swift. It has been designed to be easy to use and is compatible with both iOS and macOS.

Related Tags

  • oauthswift
  • aswebauthenticationsession
  • oauth swiftui
  • swiftui oauth2 example
  • swiftui authentication
Skip to content