gpt4 book ai didi

swift - TwitterKit 登录总是第一次尝试失败然后第二次尝试成功(Swift、TwitterKit、Firebase)

转载 作者:可可西里 更新时间:2023-11-01 01:57:17 28 4
gpt4 key购买 nike

我正在使用 TwitterKit 和 Firebase 来允许用户使用 Twitter 登录。我第一次尝试使用 Twitter 登录时失败并显示错误:

[TwitterCore] Cannot verify session credentials. 2018-07-11 13:57:20.999365-0400 social_notes[6794:1892888] [TwitterKit] did encounter error with message "Failed to save session": Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x1c044dcb0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://api.twitter.com/1.1/account/verify_credentials.json, NSErrorFailingURLKey=https://api.twitter.com/1.1/account/verify_credentials.json, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSLocalizedDescription=The network connection was lost.} 2018-07-11 13:57:21.413753-0400 social_notes[6794:1892888] [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings" UserInfo={NSLocalizedDescription=Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings} Twitter Login Error: Request failed: forbidden (403)

但是,如果我再次尝试使用 Twitter 登录,它就可以正常工作。

信息.plist

<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-XXX</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitter</string>
<string>twitterauth</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>

应用委托(delegate)

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()

window?.rootViewController = UINavigationController(rootViewController: ViewController())

FirebaseApp.configure()

Twitter.sharedInstance().start(withConsumerKey:"XXX", consumerSecret:"XXX")

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return Twitter.sharedInstance().application(app, open: url, options: options)
}

Twitter 登录按钮代码

 let twitterLoginBtn = TWTRLogInButton { (session, err) in
if let err = err {
print("Twitter Login Error: \(String.init(describing: err.localizedDescription))")
return
}
guard let token = session?.authToken else { return }
guard let secret = session?.authTokenSecret else { return }
let credential = TwitterAuthProvider.credential(withToken: token, secret: secret)

Auth.auth().signIn(with: credential, completion: { (user, err) in

etc etc....

最佳答案

这显然是一个 TwitterKit 问题。我就是这样解决的:

    let store = TWTRTwitter.sharedInstance().sessionStore
store.reload()
for case let session as TWTRSession in store.existingUserSessions() {
store.logOutUserID(session.userID)
}

关于swift - TwitterKit 登录总是第一次尝试失败然后第二次尝试成功(Swift、TwitterKit、Firebase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51292316/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com