是否可以通过 API 在 iOS 应用程序中创建可嵌入的推文,而无需用户登录 Twitter?
Is it possible to create embeddable tweets in an iOS app through the API without having users log in to Twitter?
Twitter API 是否提供此类功能?我可以在这里和那里显示一条推文(这是一个节省 link 的应用程序)并通过 API?[=12 获取推文的信息(转推、推文文本等) =]
我知道如果用户通过 OAuth 登录到我的应用程序我可以这样做,但是如果我只是想在不让用户登录的情况下到处显示推文的预览怎么办?这样的事情可能吗?
1) Install Twitter via CocoaPods
2) 更新您的 ConsumerKey 和 consumerSecret
AppDelegate.swift
import TwitterKit
var window: UIWindow?
let viewController = ViewController()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.rootViewController = self.viewController
self.window!.makeKeyAndVisible()
Twitter.sharedInstance().startWithConsumerKey("################", consumerSecret: "################")
return true
}
ViewController.swift
import TwitterKit
override func viewDidLoad() {
super.viewDidLoad()
TWTRAPIClient().loadTweetWithID("631879971628183552") { (tweet, error) in
if let unwrappedTweet = tweet {
let tweetView = TWTRTweetView()
tweetView.theme = .Light
tweetView.backgroundColor = UIColor.whiteColor()
tweetView.primaryTextColor = UIColor.blackColor()
tweetView.linkTextColor = UIColor.blueColor()
tweetView.showBorder = false
tweetView.configureWithTweet(unwrappedTweet)
tweetView.delegate = self
let height = TWTRTweetTableViewCell.heightForTweet(unwrappedTweet, width: self.view.bounds.size.width - 40)
tweetView.frame = CGRect(x: 20, y: 0, width: self.view.frame.width - 40, height: height)
tweetView.center = CGPoint(x: self.view.center.x, y: self.view.center.y)
self.view.addSubview(tweetView)
} else {
print("Tweet load error: \(error!.localizedDescription)")
}
}
}
Twitter API 是否提供此类功能?我可以在这里和那里显示一条推文(这是一个节省 link 的应用程序)并通过 API?[=12 获取推文的信息(转推、推文文本等) =]
我知道如果用户通过 OAuth 登录到我的应用程序我可以这样做,但是如果我只是想在不让用户登录的情况下到处显示推文的预览怎么办?这样的事情可能吗?
1) Install Twitter via CocoaPods
2) 更新您的 ConsumerKey 和 consumerSecret
AppDelegate.swift
import TwitterKit
var window: UIWindow?
let viewController = ViewController()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.rootViewController = self.viewController
self.window!.makeKeyAndVisible()
Twitter.sharedInstance().startWithConsumerKey("################", consumerSecret: "################")
return true
}
ViewController.swift
import TwitterKit
override func viewDidLoad() {
super.viewDidLoad()
TWTRAPIClient().loadTweetWithID("631879971628183552") { (tweet, error) in
if let unwrappedTweet = tweet {
let tweetView = TWTRTweetView()
tweetView.theme = .Light
tweetView.backgroundColor = UIColor.whiteColor()
tweetView.primaryTextColor = UIColor.blackColor()
tweetView.linkTextColor = UIColor.blueColor()
tweetView.showBorder = false
tweetView.configureWithTweet(unwrappedTweet)
tweetView.delegate = self
let height = TWTRTweetTableViewCell.heightForTweet(unwrappedTweet, width: self.view.bounds.size.width - 40)
tweetView.frame = CGRect(x: 20, y: 0, width: self.view.frame.width - 40, height: height)
tweetView.center = CGPoint(x: self.view.center.x, y: self.view.center.y)
self.view.addSubview(tweetView)
} else {
print("Tweet load error: \(error!.localizedDescription)")
}
}
}