I log in my Twitter users using +[PFTwitterUtils loginWithBlock:]
method from Parse SDK. To get user profile picture I login second time with -[Twitter logInWithCompletion:]
method from Fabric TwitterKit. Is there any way to pass auth token from Parse SDK to TwitterKit and login only once ?
There is a way to export auth token and auth token secret from Parse by using PF_Twitter
class from Parse SDK. It looks like it should be possible create a TwitterKit session by using -[TWTRSession initWithSessionDictionary:]
, but Twitter docs says nothing about dictionary format and I can't get it working.
Parse
When the user is logged in using Parse's TwitterUtils you get this method called twitter
. Right now I'm using Swift, so with PFTwitterUtils.twitter()
you'll get all the data needed. I guess it should be [PFTwitterUtils twitter];
in Objective-C.
The class is PF_Twitter
on Parse.
Fabric TwitterKit
Once you get that object you'll get access to authToken
and authTokenSecret
for the current user. Then you gotta use this method from TwitterKit (Note: This will be deprecated in the future, look at the UPDATE at the bottom):
Objective-C:
[Twitter sharedInstance]
logInWithExistingAuthToken:authTokenSecret:completion:
Swift:
Twitter.sharedInstance().logInWithExistingAuthToken(authToken, authTokenSecret: authTokenSecret, completion: { (session, error) -> Void in
})
If everything went well, this will return the current session.
Documentation:
Parse:
https://parse.com/docs/ios/api/Classes/PFTwitterUtils.html#//api/name/twitter
PF_Twitter - https://parse.com/docs/ios/api/Classes/PF_Twitter.html
Fabric:
UPDATE :
I just noticed that logInWithExistingAuthToken
will be deprecated. So the best way to do this is using the TWTRSessionStore
's saveSessionWithAuthToken
method:
Twitter.sharedInstance().sessionStore.saveSessionWithAuthToken(authToken, authTokenSecret: authTokenSecret, completion: { (session, error) -> Void in
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.