1

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.

3

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:

https://docs.fabric.io/appledocs/Twitter/Classes/Twitter.html#//api/name/logInWithExistingAuthToken:authTokenSecret:completion:

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

                    })
  • Worked perfectly for me. This should be accepted as the correct answer. – user3344977 Feb 8 '16 at 22:29

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.