Getting errors from Twitter.sharedInstance () Swift 3 iOS 10

I am writing an application with Swift 3 on iOS 10. The sharedInstance() method outputs errors to the console when a user refuses to allow an account from systems or an account that is not configured (for example, "Unable to authenticate using the system account"). Errors are displayed on the console before entering closure. I will not show these errors to users in the application, for example. by alarm. This is my code:

  Twitter.sharedInstance().logIn { (session, error) in if error != nil { // print(error?.localizedDescription ?? " ") return }) 

I get this error:

 2016-11-29 14:49:09.023 CarReview[1254:31719] [TwitterKit] did encounter error with message "Unable to authenticate using the system account.": Error Domain=TWTRLogInErrorDomain Code=2 "User allowed permission to system accounts but there were none set up." UserInfo={NSLocalizedDescription=User allowed permission to system accounts but there were none set up.} 2016-11-29 14:49:09.024 CarReview[1254:31719] [TwitterKit] No matching scheme found. 2016-11-29 14:49:09.292 CarReview[1254:31719] [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?> <hash> <error>Desktop applications only support the oauth_callback value 'oob'</error> <request>/oauth/request_token</request> </hash> " UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?> <hash> <error>Desktop applications only support the oauth_callback value 'oob'</error> <request>/oauth/request_token</request> </hash> } 

I want to show users the following: "Authentication using the system account failed. The user allowed access to the system accounts, but was not installed."

+6
source share
5 answers

I ran into the same problem as in the question. I just installed callBack Url in my Twitter app and solved the problems.

Go to https://apps.twitter.com/app → Settings → Callback URL and update options to save.

+10
source

I'm not sure I understand what you want to do, but you probably want to print the result in the main thread:

 Twitter.sharedInstance().logIn{(session, error) in DispatchQueue.main.async{ if error != nil { print("Failed to login with Twitter / error:", error!.localizedDescription) }else{ print("succeeded") } } } 
0
source

OK, I use this code to notify the user of some error:

 if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) { if ACAccountStore().accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter).accessGranted { Twitter.sharedInstance().logIn{ (session, error) in if error != nil { self.showAlert(title: "Twitter - Error", message: (error?.localizedDescription)!) return } guard let token = session?.authToken else { return } guard let secret = session?.authTokenSecret else { return } let credential = FIRTwitterAuthProvider.credential(withToken: token, secret: secret) FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in if error != nil { self.showAlert(title: "Firebase (Twitter)", message: (error?.localizedDescription)!) return } self.showAlert(title: "Firebase (Twitter)", message: "Logged to Firebase via Twitter.") }) } } else { showAlert(title: "Twitter - Error", message: "Give access to the system Twitter account.") } } else { showAlert(title: "Twitter - Error", message: "No system accounts set up.") } 

But this is not what I want: /

0
source

You need to use withMethods and specify using systemAccounts, not webBased or all, in order to use the Twitter iOS settings. The following code is in Swift 3:

 twitSharedInstance.logIn(withMethods: .systemAccounts) { (session :TWTRSession?, error :Error?) in if (error != nil) { if (session != nil) { //We have logged into Twitter. } } } 
0
source

I will try to guess what your question really is:

"I have these errors in the console, but callback is not called, so I can not notify the user. What should I do with this?"

You get these errors because your consumerKey and consumerSecret not been set to Info.plist. You need to install the Twitter SDK correctly

This is what is written in the comments on logIn(completion:)

@warning This method requires you to set consumerKey and consumerSecret .

Your Info.plist should have something like this (note the lines <key>consumerKey</key> and <key>consumerSecret</key> ):

 <key>Fabric</key> <dict> <key>APIKey</key> <string> YOUR API KEY </string> <key>Kits</key> <array> <dict> <key>KitInfo</key> <dict> <key>consumerKey</key> <string> YOU PROBABLY MISSED YOUR CONSUMER KEY </string> <key>consumerSecret</key> <string> YOU PROBABLY MISSED YOUR CONSUMER SECRET </string> </dict> <key>KitName</key> <string>Twitter</string> </dict> </array> </dict> 
0
source

Source: https://habr.com/ru/post/1012720/


All Articles