0

I am trying to add Twitter login to my Xcode project. My main login is Facebook but my app uses Twitter info and since ACAccountStore().requestAccessToAccounts is deprecated for iOS 11, I have to use the Twitter API. I installed the TwitterKit pod. I added the following to my app 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)
}

and my plist looks like:

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

now I have a view controller where I am adding the login button like so:

    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) 

when I click the button, I am getting Request failed: unauthorized (401) in the console. If I build it on my iPod using 11.2.1 the login will open since I have the Twitter app installed on this device. I included SafariServices.framework and I followed all of the Twitter instructions. Any thoughts?

Sente
  • 277
  • 4
  • 11
  • Possible duplicate of [iOS TWTRComposer Request failed: unauthorized (401)](https://stackoverflow.com/questions/44491349/ios-twtrcomposer-request-failed-unauthorized-401) – Mo Abdul-Hameed Jan 01 '18 at 00:42
  • yes, I saw that too. It didn't solve anything – Sente Jan 01 '18 at 00:48

1 Answers1

0

In Twitter Application Management I set the callback URL to https://placeholder.com/ and it works now

Sente
  • 277
  • 4
  • 11