skip to Main Content

i want to make app that login with twitter so i want to fetch some data from twitter account such as id,username, and email.

i have an api that take the 3 parameters and return success so i want to get the 3 parameters.

i have a custom button and i want when i tap this button i want to get twitter page and after i write username and password i want to fetch data

i configure twitter and fabric account.

i only want a function to fetch this data for me.

thanks in advance

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    Fabric.with([TWTRTwitter.self])


    // twitter configration

    TWTRTwitter.sharedInstance().start(withConsumerKey:"----------", consumerSecret:"-------")


    return true
}

2

Answers


  1. You can fetch data from twitter by using following method:

    Twitter.sharedInstance().logIn { (session, error) in
    
                if (session != nil) {                
                    let credential = TwitterAuthProvider.credential(withToken: (session?.authToken)!, secret: (session?.authTokenSecret)!)
    
                    let username = session?.userName
                    let userId = session?.userID
    
                    print("Username: (username ?? "")")
                    print("UserId: (userId ?? "")")
    
    
                    let client = TWTRAPIClient.withCurrentUser()
                    client.requestEmail(forCurrentUser: { (email, error) in
                        if error == nil{
                            if email != nil{
                                let email = email
                                print("Email: (email ?? "")")
                            }
                        }else{
                            print("error: (error?.localizedDescription ?? "")")
                        }
                    })
    
                }else{
                    print("error: (error?.localizedDescription ?? "")")
                }
    }
    

    Hope this will help you.

    Login or Signup to reply.
  2. Declare variable:

    var twiterUserdata: [String:Any] = [:]
    

    function for get user Info:

     func twitterUserInfo(){
            TWTRTwitter.sharedInstance().logIn(completion: { (session, error) in
                let client = TWTRAPIClient.withCurrentUser()
                client.requestEmail { emailId, error in
                    if (emailId != nil) {
                        let name = session?.userName
                        let email = emailId
                        self.twiterUserdata["name"] = name
                        self.twiterUserdata["email"] = email
                        TWTRTwitter.sharedInstance().sessionStore.session()
                        print(self.arrTwiterUserdata)
                    } else {
                        print("error: (String(describing: error?.localizedDescription))");
                    }
                }
            })
        }
    

    Hope It’s helps to you.!!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search