How to detect that user has revoked access in iOS app




This is my pod configuration:
pod ‘TwitterKit’, ‘3.3.0’
pod ‘TwitterCore’, ‘3.1.0’

My code to detect there is a user logged to compose Tweets:

if TWTRTwitter.sharedInstance().sessionStore.hasLoggedInUsers() {
        } else {
            }, failure: { (error) in
                print("not logged: \(error.debugDescription)")
                let alert = UIAlertController(title: "Message_Title_Not_Twitter_Account".localized(), message: "Message_Text_Not_Twitter_Account".localized(), preferredStyle: .alert)
                 alert.addAction(UIAlertAction(title: "Message_ok".localized(), style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: false, completion: nil)

The code works perfect but once the user revoke the access to the app, the compose appear and when user send a pop up appear:

Tweet failed to send

Is there any way to detect the user has revoked the app to launch the login process?

Thank you


There’s no built-in method for this in Twitter Kit itself, but you could call the account/verify_credentials endpoint using the ApiClient to check whether the user’s tokens are valid - that would tell you if the user had revoked the app or not.


Thanks for your answer @andypiper
That’s is I need.

Could you show me how to call account/verify_credentials endpoint? Maybe exist some example or a link to the documentation.


The API documentation is here, I’d suggest using the API Client in Twitter Kit to call it.


Thank you so much.
Right now is working.

I’m verifying the account with this method:

let userID = TWTRTwitter.sharedInstance().sessionStore.session()?.userID
let client = TWTRAPIClient(userID: userID)
var clientError : NSError?
let request = client.urlRequest(withMethod: "GET", urlString: "", parameters: nil, error: &clientError)
client.sendTwitterRequest(request) { (response, data, error) in
            if error != nil {