7

我正在 iOS 10 上使用 Swift 3 编写应用程序。sharedInstance()当用户拒绝来自系统的帐户权限或未配置帐户(例如“无法使用系统帐户进行​​身份验证”)时,方法会向控制台抛出错误。在进入关闭之前,控制台上会显示错误。我不会在应用程序中向用户显示此错误,例如处于警报状态。这是我的代码:

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

我收到此错误:

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>
}

我想向用户展示:“无法使用系统帐户进行​​身份验证。用户允许系统帐户的权限,但没有设置。”

4

4 回答 4

13

我面临与问题相同的问题。我刚刚将回调 URL 设置到 Twitter 应用程序中并解决了问题。

转到https://apps.twitter.com/app -> 设置 -> 回调 URL 和更新设置以保存。

于 2017-05-25T12:05:16.163 回答
0

好的,我使用此代码通知用户一些错误:

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.")
        }

但这不是我想要的:/

于 2016-11-29T16:22:14.403 回答
0

您需要使用 withMethods 并指定使用 systemAccounts,而不是 webBased 或 all 以使用 iOS Twitter 设置。以下代码在 Swift 3 中:

twitSharedInstance.logIn(withMethods: .systemAccounts) { (session :TWTRSession?, error :Error?) in
        if (error != nil) {
            if (session != nil) {
                //We have logged into Twitter.
            }
        }
    }
于 2017-03-24T02:52:12.893 回答
0

我不确定我是否理解您想要做什么,但您可能想在主线程上打印结果:

Twitter.sharedInstance().logIn{(session, error) in
    DispatchQueue.main.async{
        if error != nil {
            print("Failed to login with Twitter / error:", error!.localizedDescription)
        }else{
            print("succeeded")
        }
    }
}
于 2016-11-29T10:55:02.253 回答