早晨
我试图将Twitter登录集成到我的应用程序中,所以我使用了swifter框架。
我可以找到user_id和screen_name。
但是我也希望用户电子邮件吗?
我尝试了此代码
@IBAction func didTouchUpInsideLoginButton(_ sender: AnyObject) {
let failureHandler: (Error) -> Void = { error in
self.alert(title: "Error", message: error.localizedDescription)
}
if useACAccount {
let accountType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
// Prompt the user for permission to their twitter account stored in the phone's settings
accountStore.requestAccessToAccounts(with: accountType, options: nil) { granted, error in
guard granted else {
self.alert(title: "Error", message: error!.localizedDescription)
return
}
let twitterAccounts = self.accountStore.accounts(with: accountType)!
if twitterAccounts.isEmpty {
self.alert(title: "Error", message: "There are no Twitter accounts configured. You can add or create a Twitter account in Settings.")
} else {
let twitterAccount = twitterAccounts[0] as! ACAccount
self.swifter = Swifter(account: twitterAccount)
self.fetchTwitterHomeStream()
}
}
} else {
let url = URL(string: "swifter://success")!
if #available(iOS 9.0, *) {
swifter.authorize(withCallback: url, presentingFrom: self, success: { credential, _ in
self.fetchTwitterHomeStream()
}, failure: failureHandler)
} else {
// Fallback on earlier versions
}
}
}
该功能使我可以获取所有用户详细信息,但没有电子邮件
func fetchTwitterHomeStream() {
let failureHandler: (Error) -> Void = { error in
self.alert(title: "Error", message: error.localizedDescription)
}
swifter.verifyAccountCredentials(includeEntities: false, skipStatus: false, includeEmail: true, success: { (json) in
print(json)
}, failure: failureHandler)
}