我正在尝试将 Twitter 登录添加到我的 Xcode 项目中。我的主要登录是 Facebook,但我的应用程序使用 Twitter 信息,并且由于 ACAccountStore().requestAccessToAccounts 在 iOS 11 中已弃用,因此我必须使用 Twitter API。我安装了 TwitterKit pod。我将以下内容添加到我的应用程序委托(delegate)中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Database.database().isPersistenceEnabled = true
Twitter.sharedInstance().start(withConsumerKey: "the key from twitter", consumerSecret: "the secret from twitter")
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
我的plist看起来像:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fbxxxxxx</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-xxxxx</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>FacebookAppID</key>
<string>xxxxx</string>
<key>FacebookDisplayName</key>
<string>Smartter</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>twitter</string>
<string>twitterauth</string>
</array>
现在我有一个 View Controller ,我在其中添加登录按钮,如下所示:
let logInButton = TWTRLogInButton(logInCompletion: { session, error in
if (session != nil) {
print("signed in as \(session?.userName)");
} else {
print("error: \(error?.localizedDescription)");
}
})
logInButton.center = self.view.center
self.view.addSubview(logInButton)
当我单击该按钮时,我在控制台中收到“请求失败:未经授权 (401)”。如果我使用 11.2.1 在 iPod 上构建它,则登录将打开,因为我在此设备上安装了 Twitter 应用程序。我包含了 SafariServices.framework 并遵循了所有 Twitter 说明。有什么想法吗?
最佳答案
在 Twitter 应用程序管理中,我将回调 URL 设置为 https://placeholder.com/现在可以使用了
关于swift - Twitter 登录未在 Xcode 模拟器中启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48046515/