我使用TwitterKit和Firebase来允许用户使用Twitter登录。当我第一次尝试使用Twitter登录时,它出现了错误:
TwitterCore无法验证会话凭据。2018-07-11 13:57:20.999365-0400 social_notes6794:1892888确实遇到了错误,消息是“未能保存会话”:error Domain=NSURLErrorDomain Code=-1005“网络连接丢失了”。UserInfo={NSUnderlyingError=0x1c044dcb0 {错误Domain=kCFErrorDomainCFNetwork代码=-1005 "(null)“UserInfo={_kCFStreamErrorCodeKey=57,_kCFStreamErrorDomainKey=1 }、NSErrorFailingURLStringKey=credentials.json、NSErrorFailingURLKey=credentials.json、_kCFStreamErrorDomainKey=1、_kCFStreamErrorCodeKey=57、NSLocalizedDescription=The网络连接丢失。} 2018-07-11 13:57:21.413753-0400 social_notes6794:1892888确实遇到了”错误获取用户令牌“消息。:error Domain=TWTRLogInErrorDomain Code=-1”未批准此客户端应用程序的回调URL。可在应用程序设置中调整已批准的回调URL“UserInfo={NSLocalizedDescription=Callback URL未批准此客户端应用程序。可在应用程序设置中调整已批准的回调URL} Twitter登录错误:请求失败:禁止(403)
但是如果我第二次尝试用Twitter登录,它就可以正常工作了。
Info.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>应用程序代表
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....发布于 2018-10-13 17:25:15
这显然是一个TwitterKit问题。我就是这样解决的:
let store = TWTRTwitter.sharedInstance().sessionStore
store.reload()
for case let session as TWTRSession in store.existingUserSessions() {
store.logOutUserID(session.userID)
}https://stackoverflow.com/questions/51292316
复制相似问题