iosswifttwitterkit

Login with twitter always return error


I am try to add login with twitter but some how I am not able to get response. Everytime I got the error message (error obtaining user auth token). I know there are lot's SO post which has this issue but I am not able to login. I also try advance setting but I got session nil. I also regenerate the consumer key and Secret but no luck. using swift 3.0

Here is my code

TWTRTwitter.sharedInstance().logIn(with: self) { (session, error) in
     if (session != nil) {
     print("signed in as \(session?.userName ?? "")");
            } else {
                print("error: \(error?.localizedDescription ?? "")");
            }
     }

info.plist

enter image description here

Appdelegate

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        _ = DBSingleton.sharedInstance
        TWTRTwitter.sharedInstance().start(withConsumerKey:TwitterKey.consumerKey, consumerSecret:TwitterKey.consumerSecret)
}

attached log screenshot

Update: if we have application then it works fine but if not then it return errors.


Solution

  • After lot of R&D I got the success. Twitter has made call back url compulsory. I found from this link

    You need to add twitterkit-xxxxxxxxxxxxxxxx (twitterkit-consumer key) in call back url at twitter dashboard setting.

    I used this method for opening safari (make sure you add safari framework)

    TWTRTwitter.sharedInstance().logIn(with: self) { (session, error) in
                if (session != nil) {
                    print("signed in as \(session?.userName ?? "")");
                } else {
                    print("error: \(error?.localizedDescription ?? "")");
                }
            }