2017-04-25 5 views
0

사용하여 트위터에서 이메일을 얻으려고 노력 무기 호 :스위프트 3 : 내가 트위터에서 사용자의 이메일을이 문을 사용하고 직물

I tested this code and it returns a nil for the email address!          ` 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 
         if (connectionError == nil) { 

          do{ 
           let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String:Any] 
           print("Json response: ", json) 
           let firstName = json["name"] 
           let lastName = json["screen_name"] 
           let email = json["email"] 
           print("First name: ",firstName!) 
           print("Last name: ",lastName!) 
           print("Email: ",email!) 
          } catch { 

          } 

         } 
         else { 
          print("Error: \(connectionError)") 
         } 
        } 

`

그러나 불행하게도이 전무 반환!

나는 이미 내 앱을 화이트리스트에 올렸고 트위터 팀으로부터 모든 권한이 내 앱에 부여되었다는 이메일을 받았다.

email from Twitter

+0

응답에서 emailID를 반환하는 Twitter API 중지. –

답변

1

앱과 트위터 SDK와 어떤 구성 문제가 없습니다. 사용자가 자신의 프로필 개인 정보 설정에서 Email 필드에 대한 액세스를 허용하지 않았기 때문에 아무런 답례가 없습니다. 프라이버시 설정을 변경하고 코드에서이 값을 가져올 수 있습니다. OR 사용자가 계정에 이메일 ID를 추가하지 않았습니다.

+0

동일한 Twitter 계정을 사용하여 Android 애플리케이션에서 이메일을받습니다. 그리고 Fabric docs에서 코드를 사용하지 않아도되었습니다. [link] (https://docs.fabric.io/apple/twitter/log-in-with-twitter.html#request-user-email-address) –

0

API는 귀하에게 이메일 주소를 반환하지 않습니다. 사용자의 전자 메일 주소에 관심이 있다면 사용자는 자신의 응용 프로그램 내에서 완전히 구별되는 행동으로 사용자에게 요청해야합니다.

+0

코드 스 니펫을 줄 수 있습니까? –

+0

// 스위프트 하자 클라이언트 = TWTRAPIClient.clientWithCurrentUser() 하자 요구 = client.URLRequestWithMethod ( URL을 "GET": "https://api.twitter.com/1.1/account/verify_credentials.json" 매개 변수 :오류 : nil) client.sendTwitterRequest (req) {응답, 데이터, connectionError} – KKRocks

+0

확인 : https : //docs.fabric ([include_email ":"true ","skip_status " .io/apple/twitter/log-in-with-twitter.html – KKRocks