TwitterKit 3.0.3 Failed authorization for iOS

ios
oauth

#1

I used this official Guide from Twitter for Log In

My steps:

  1. Callback URL leave field blank in Application Management

  2. Install pods pod 'Fabric', pod 'TwitterKit'

  3. Add on Info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>twitterkit-xxxxxxxx</string>
            <string>fbxxxxxxxx</string>
        </array>             
    </dict>
</array>
<key>FacebookAppID</key>
<string>xxxxx</string>
<key>FacebookDisplayName</key>
<string>Name</string>    
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>twitter</string>
    <string>twitterauth</string>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>
<key>Fabric</key>
<dict>
  <key>APIKey</key>
  <string>xxxxxxxxxx</string> 		
  <key>Kits</key>
  <array>
      <dict>
  		<key>KitInfo</key>
  		<dict/>
  		<key>KitName</key>
  		<string>Crashlytics</string> 
     </dict>
</array>
</dict>
  1. Add on class AppDelegate

     import TwitterKit
     ....
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
         ....
         Twitter.sharedInstance().start(withConsumerKey:"xxxxxx", consumerSecret:"xxxxx") 
     }
     func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {    
         return Twitter.sharedInstance().application(app, open: url, options: options)
     }
    
  2. Add Frameworks:
    enter image description here

  3. Add on Header.h #import <TwitterKit/TwitterKit.h>

  4. Add TwitterLogInButton from official Guide

When I click the button to log in, I get an error (test was conducted on a Simulator iOS 9.3):

-canOpenURL: failed for URL: "twitterauth://authorize?consumer_key=xxxSAMExxx&consumer_secret=yyyyyyy&oauth_callback=twitterkit-xxxSAMExxx" - error: "(null)"
[TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>
}

#2

2 things:

  1. I’m pretty sure you need a “placeholder” callback URL instead of leaving it blank. (says so on the ‘Getting Started’ page: item 3 under ‘To add call back URL:’)

  2. I got the same error when using the simulator: you might try it on a device - the SDK thinks you are using it from a desktop, not mobile, because it is running on the simulator.

Full disclosure: haven’t gotten Login working for my app yet!!!