Ios swift user email missing from credential response

ios
login
email

#1

Hello,

I have been using fabric to build twitter login, everything goes fine except i am missing the email that i need. I do however get the email on my android version of the app we build. The app is whitelisted and all and it works on android so i am unsure what i am doing wrong here.

I am using the following piece of code.

let logInButton = TWTRLogInButton { (session, error) in
            if session != nil {
                
                print("signed in as \(session!.userName)");
                
                let client = TWTRAPIClient.clientWithCurrentUser()
                let request = client.URLRequestWithMethod("GET",
                    URL: "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true",
                    parameters: ["include_email": "true", "skip_status": "true"],
                    error: nil)
                
                
                client.sendTwitterRequest(request) { response, data, connectionError in
                    if (connectionError == nil) {
                        
                        let json : AnyObject
                        
                        do{
                            json = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
                            
                            print("Json response: ", json)
                            
                            let firstName = json["name"]
                            let lastName = json["screen_name"]
                            let email = "-"
                            
                            print("First name: ",firstName)
                            print("Last name: ",lastName)
                            print("Email: ",email)
                            
                            
                        } catch {
                            
                        }
                        
                    }
                    else {
                        print("Error: \(connectionError)")
                    }
                }
                
                
            } else {
                NSLog("Login error: %@", error!.localizedDescription);
            }
        }

the json response just isn’t showing the email, everything else is there.

What should i do?


#2

Hey @carlosx2,

If the response isn’t showing up in the json, usually one of three things are happening.

  1. The key doesn’t have permissions to view the email address, but it sounds like this one isn’t true.
  2. The user either chose to not give this out.
  3. The user already authenticated your app before email address permission was given. In this case, a quick test is to revoke access from Twitter for the app. Head to https://twitter.com -> Settings -> Apps and revoke access for your app. Then re-authenticate and the address should show up.

-Mike


#3

I am not sure if i even have a key set in this code. I know i used the key and secret on the android app and that all works. I also revoked the access and loggedout of twitter to see if that did the trick, but it didn’t.

How should i add the keys in this one as it all seems to work without me adding any keys.


#4

I remember that the keys and secret where setup by fabric so that should also be setup correctly. But i just can’t get the email. also when i revoke access, the app doesn’t ask me for permission. It is only when i signout of twitter it is asking me again and then it doesn’t say that the app would like to have access to me email. When i do the same with my android version of the app it does shows me on the permission screen that the app wants to get my email.

Seems something is missing in the code it seems or the not passed by the api.


#5

Gotcha, Fabric based keys by default do not include permission to access the email address. You mentioned that the key was whitelisted, but I’d love to check. Can you email the Twitter Consumer Key you’re using into support(at)fabric(dot)io and reference this thread?


#6

I will send an email, but i did the whole whitelisting thing as i already did it for the android app before.