- Twitter OAuth Authentication
- OAuth
- iOS internal twitter account
- App Only Authentication
- Twitter REST APIs
- Installation
- Cocoapods
- Carthage
- Swift Package Manager
- Document
- Platform
- iOS
- Mac
- Linux
- tvOS
- watchOS
iOS 11.0+
pod 'Twifter'
github 'simorgh3196/Twifter'
.package(url: "https://github.com/simorgh3196/Twifter.git", .upToNextMajor(from: "0.2.0")),
- Set
URL Types
inInfo.plist
- Set ConsumerToken, Secret and OAuth callback handler in
AppDeleagte.swift
import UIKit
import Twifter
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Set consumerToken and consumerSecret
Twifter.registerConsumerKey(token: "*************************",
secret: "**************************************************")
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
// Set handler of twitter oauth callback
Twifter.handleOpenURL(url: url)
return true
}
}
callbackURL is defined by URL Types
in Info.plist
let callbackURL = URL(string: "twifter://")!
Twifter.authentication(viewController: self, callbackURL: callbackURL, handler: { result in
switch result {
case .success(let accessToken):
print("success!!!")
print("AccessToken is " + accessToken)
case .failure(let error):
print(error)
}
})
let twifter = Twifter(accessToken: accessToken)
twifter.getTimeline { tweets in
print(tweets)
}
TODO
Bug reports and pull requests are welcome on GitHub at https://github.com/simorgh3196/Twifter.
The module is available as open source under the terms of the MIT License.