Custom twitter login button and get email address

fabric
login
swift
email

#1

Hi there.

I have this code block for custom twitter login button:

@IBAction func twitter(_ sender: Any) {
    
    Twitter.sharedInstance().logIn(withMethods: [.webBased]) { session, error in
        if (session != nil) {
            
            let client = TWTRAPIClient.withCurrentUser()
            let request = client.urlRequest(withMethod: "GET", url: "https://api.twitter.com/1.1/account/verify_credentials.json", parameters: ["include_email": "true", "skip_status": "true"], error: nil);
            
            client.sendTwitterRequest(request) { response, data, connectionError in
                
                let json = JSON(data: data!);
            
                print(json);
                
            }
            
        } else {
            
            print( error?.localizedDescription );
            
        }
    }
    
}

First question is what is currently login type (withMethods) parameters. Like, webBased.

Example, can I use .appBased or etc?

2 - print(json); looks pretty good, but I still need the email address. How can I get it?

Thank you!


#2

Hey @Eggdrop,

Requesting an email address from a user requires your app to be whitelisted by the Fabric team. Please email into support(at)fabric(dot)io with your Twitter Consumer Key and link to your Privacy Policy!

-Mike


#3

Hi Mike,

Thank you for your interest.

I created new application at apps.twitter.com and I requested for permission. They are give permission to me.

But I’m trying with new keys. Result is same. I still can’t see the email fields.

Whats wrong?


#4

I found the problem:

This work:
Twitter.sharedInstance().logIn(withMethods: [.webBased])

This wont work:
Twitter.sharedInstance().logIn()

Thank you all!