swift - Twitter 登录未在 Xcode 模拟器中启动

标签 swift xcode twitter

我正在尝试将 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/

相关文章:

c++ - Xcode需要哪些设置才能构建此代码

ios - Swift (Xcode) - 从表格单元格传递值到下一个 Controller -> Action 按钮 -> Segue

jquery - 仅将文本颜色添加到 HTML 推文的主题标签

python - 为什么我在使用 Twitter Rest API 时收到此错误

swift - 如何在远程服务器中持久保存 HKQueryAnchor

ios - 按下表格 View 单元格时如何添加深色?

ios - 使用 CoreNFC 检测 ISO/IEC 14443(Mifare Ultralight 或 Classic)NFC 卡

ios - 蓝牙外围设备不应答

java - 为什么此代码会在 sleep 时导致 NPE 以避免 Twitter4J 中的速率限制?

ios - 如何防止 subview 重叠其父级ScrollView?