Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lam

I tried to run your code with my API key and API secret key. I saw that app show page api.twitter.com –> I logged in successfully –> click button Authorize app –> call callbackURL. I can’t access token back when calling:

func authorize(withCallback callbackURL: URL,
          presentingFrom presenting: UIViewController?,
          forceLogin: Bool = false,
          safariDelegate: SFSafariViewControllerDelegate? = nil,
          success: TokenSuccessHandler?,
          failure: FailureHandler? = nil).

Do you know why?
Thanks a lot for your post.

Lam

Yes, I registered my app on https://developer.twitter.com, so I got API key and API secret key.

das

The callback is always going to return true. Please have a look. Return should be from the function handleOpenURL itself.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let callbackUrl = URL(string: TwitterConstants.CALLBACK_URL)!
    Swifter.handleOpenURL(url, callbackURL: callbackUrl)
    return true
  }

I would write it this way.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let callbackUrl = URL(string: TwitterConstants.CALLBACK_URL)!
    return Swifter.handleOpenURL(url, callbackURL: callbackUrl)
  }
das

Yeah true. It fits for the demo app but not if you have several callbacks from different processes … then it could be problematic.