Get Email Twitter in Swift 3

ios
login
swift

#1

Hi.
I follow the tutorial for get email.
When i press the login button (via Twitter.sharedInstance().logIn(withMethods: [.webBased])…) in Swift 3, the ViewController disappear and i get back to the rootviewcontroller and received this error in console.

[TwitterKit] did encounter error with message “Error obtaining user auth token.”: Error Domain=TWTRLogInErrorDomain Code=-1 “<?xml version="1.0" encoding="UTF-8"?>

Desktop applications only support the oauth_callback value ‘oob’
/oauth/request_token

” UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>

Desktop applications only support the oauth_callback value ‘oob’
/oauth/request_token

}
Error: Optional(“Request failed: unauthorized (401)”).

I have added the URL Scheme and the SafariServices.framework

This is my Appdelegate method

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if Twitter.sharedInstance().application(app, open:url, options: options) {
return true
}

    // If you handle other (non Twitter Kit) URLs elsewhere in your app, return true. Otherwise
    return false
}

And my ViewController

Twitter.sharedInstance().logIn(withMethods: [.webBased]) { session, error in
if session != nil {
print(“UserName: (session?.userName)”)

            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
                print("Email: this work")
            }
            
        } else {
            print("Error: \(error?.localizedDescription)")
        }
    }

Sorry my english, my native is Spanish


#2

Hey @MZapatae,

Thanks for reaching out on this! Has your app been whitelisted to get the email address from a user? If not, please let me know the bundle id or package name of your app.

-Mike