Processing
 

Twitter OAuth on iOS

19/08/2016 10:22#1

Joined at: 4 months ago

Post: 2

Thank: 0

Thanked: 0

I need to register on our server via twitter. I made registration with help of OAuth. When we make any request on our server we check our token is active, if our token is expired we make resign on our server and I need to resign in Twitter session, I do logout, but session is active. Android team do it with help

TwitterCore.getInstance().getSessionManager().clearActiveSession(); TwitterCore.getInstance().logOut(); 

. How can I do it on iOS? I use Swift Please, help me.

My code

func auth(userEmail: String?, successLoginCallback: ((usr : User) -> Void)?, failLoginCallback: ( (message: String) -> Void )?) {     Twitter.sharedInstance().sessionStore.reloadSessionStore()     Twitter.sharedInstance().startWithConsumerKey(twitterKey, consumerSecret: twitterSecret)     Twitter.sharedInstance().logInWithCompletion { (session, error) in         if session != nil {             TWTRAPIClient.clientWithCurrentUser().requestEmailForCurrentUser({ (twitterEmail, error) in                 // oauth parameters                 let oauthSession = TWTRSession(authToken: session!.authToken, authTokenSecret: session!.authTokenSecret, userName: session!.userName, userID: session!.userID)                  let oauthSigning = TWTROAuthSigning(authConfig: Twitter.sharedInstance().authConfig, authSession: oauthSession)                 let headers = oauthSigning.OAuthEchoHeadersToVerifyCredentials()                 guard let authHeaders = headers as? [String : AnyObject] else {                     return                 }                 var passEmail: String?                 if userEmail != nil {                     passEmail = userEmail                 }                 UserManager.sharedManager.logInViaTwitter(passEmail, parameters: authHeaders, success: { (user) in                     self.userIsLogginedViaTwitter = true                     self.twitterSuccessLogin(user)                     print("user token", user.token?.expr)                     successLoginCallback?(usr: user)                     }, fail: { (errorMessage) in                         if errorMessage != nil {                             self.twitterFailsLogin(errorMessage!)                             failLoginCallback?(message: errorMessage!)                         }                 })             })         }         if error != nil {             print(error?.localizedDescription)         }     } }   func logOut(success: (() -> ())?) {         Twitter.sharedInstance().startWithConsumerKey(twitterKey, consumerSecret: twitterSecret)         guard let userID = Twitter.sharedInstance().sessionStore.session()?.userID else { return }         Twitter.sharedInstance().sessionStore.logOutUserID(userID)         userIsLogginedViaTwitter = false         let cookieStorage: NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage()         cookieStorage.cookies?.forEach({ (cook) in             cookieStorage.deleteCookie(cook)         })         success?()     }     // MARK: - Twitter functions      func logInViaTwitter(email: String?, parameters: [String : AnyObject], success: ((user: User) -> ())?, fail: ((errorMessage: String?) -> ())?) {         let url = "\(Networking.baseUrl)/auth/login/tw"         guard let oauth_url = parameters["X-Auth-Service-Provider"] as? String else { return }         guard let oauth_params = parameters["X-Verify-Credentials-Authorization"] as? String else { return }         var passParameters = [String : AnyObject]()         if email != nil {             passParameters = ["email" : email!, "oauth_url" : oauth_url, "oauth_params": oauth_params]         } else {             passParameters = ["oauth_url" : oauth_url, "oauth_params": oauth_params]         }         print("Twitter manager passParameters", passParameters, "Twitter manager passParameters")          Networking.manager.request(.POST, url, parameters: passParameters, encoding: .JSON, headers: nil).responseObject { (response: Response<RegisterResponse, NSError>) in             guard let result = response.result.value else {                 fail?(errorMessage: nil)                 return             }              if result.meta?.errors.count == 0 {                 print(result.response)                 guard let user = Mapper<User>().map(result.response) else {                     fail?(errorMessage: nil)                     return                 }                 // Save state in Twitter manager                 TwitterManager.sharedManager.userIsLogginedViaTwitter = true                 self.saveCurrentUser(user)                 success?(user: user)             } else {                 fail?(errorMessage: result.meta?.errors.first?.message)             }          }     } 
02/09/2016 19:46Top#2

Joined at: 4 months ago

Post: 2

Thank: 0

Thanked: 0

We have changed the query logic, so that with every request we did not request information from the Twitter framework.

Similar articles

How do twitter giveaways work?

8 months ago - Reply: 2 - Views: 126

How may I get genuine followers on Twitter?

3 years ago - Reply: 33 - Views: 1,828

Login to Twitter sometime fail

6 months ago - Reply: 1 - Views: 23

Twitter doesn't accept PHP's cURL, but Linux'

1 year ago - Reply: 2 - Views: 90

Twitter OAuth on iOS

5 months ago - Reply: 1 - Views: 92

why am i getting an error on .verifyCredentials()

5 months ago - Reply: 1 - Views: 35

TwitteR setup_twitter_oauth() gives an error

5 months ago - Reply: 1 - Views: 29

Tweepy - Getting the author of a retweeted tweet

5 months ago - Reply: 0 - Views: 4

Retrieving data from twitter with JavaScript

5 months ago - Reply: 0 - Views: 2

Combined social media feed returning the wrong data

5 months ago - Reply: 0 - Views: 0

Django and Twitter request_token

5 months ago - Reply: 0 - Views: 0

Python HMAC hashed value encoding to base64

5 months ago - Reply: 1 - Views: 32

At the rate symbol in facebook

5 months ago - Reply: 0 - Views: 1

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re