Fabric twitter session validity?


#1

Hi,
How can i know if the current session which i have is active or not ? Is there any methord to find out about sessions validity like for example facebook has this methord to find session validity

                    Session.getActiveSession().isOpened()

Any helps ??


#2

Hi,

TwitterSessions do not expire and will be valid unless the user has explicitly rejected your application from their settings or if a Twitter admin suspends your application.


#3

Thanks for your reply. But i have a concern here,

->When the user first tries to acces twitter from my application i get the session ,
-> Using this session i try to get users details , everytime he tries to login in my application

-> What if the user logs out from twitter application and signs in with other account,

->Now if he tries to login in my application i will be still getting the old users data right ?
->How will i know that the user has logged out, and how to get new users data ?


#4

Hi,

The TwitterSession that is returned to you is associated with your application. This means that it will always be a valid TwitterSession unless the user has explicitly rejected your application from their settings or if a Twitter admin suspends your application.

You are right that if the user logs out of the Twitter application and signs in with another account, then your application won’t know about the new account. Your application would have to request login for the new account.


#5

Hi,
Thats my problem too, how to know if the user has signed with a new account. If i want to request login for the new account there must be a way for me to know about the new account.
So any helps about this ??


#6

Is there a way for the app to know if the user rejected the application from their settings?


#7

Hi there @chap19150,

Currently the only way to know if the user rejected the application from their settings is if Twitter API requests made with the user access token stop working.

Lien


#8

Hi Lien,

I can check, whether the account was changed by simply comparing usernames from current session (session.username) and one, given by standard social kit:

let accountStore = ACAccountStore()
                    let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
                    let twitterAccounts = accountStore.accountsWithAccountType(accountType)
                     let twitterAccount = twitterAccounts[0] as ACAccount
                    println("real username:  \(twitterAccount.username)")

however, I don’t know, how to programmatically request renew of the session credentials, if these two usernames don’t coincide. If it is possible, it would solve the problem

Anton

solved: added

Twitter.sharedInstance().logOut()

if usernames are different


#9

Hi Anton,

Cool solution!

Unfortunately, you won’t be able to programmatically request a renew of the session credentials if the account was changed. Since it’s a different account, you have to ask the user to grant you access to the new account by starting the login flow again.

Lien