2016-06-27 2 views
0

Twitter에서 사용자의 이메일 주소를 요청하여 Firebase에 저장하려고합니다. Twitter에서 허용 된 내 앱을 apps.twitter.com 포털에서 활성화했습니다. 여기에 패브릭 문서에 따라,이 코드를 썼다 :Twitter에서 사용자의 이메일 요청

let twitterEmailClient = TWTRAPIClient.clientWithCurrentUser() 
let twitterEmailRequest = twitterEmailClient.URLRequestWithMethod("GET", URL: "https://api.twitter.com/1.1/account/verify_credentials.json", parameters: ["include_email": "true", "skip_status": "true"], error: nil) 
twitterEmailClient.sendTwitterRequest(twitterEmailRequest, completion: { (TWTREmailClientResponse: NSURLResponse?, TWTREmailClientEmail: NSData?, TWTREmailClientError: NSError?) in 

    if TWTREmailClientError != nil { 

     print("Twitter Email Client Error - \(TWTREmailClientError!.code): \(TWTREmailClientError!.localizedDescription)") 

    } else if TWTREmailClientResponse == nil { 

     print("Twitter Email Client Error - valid connection not available") 

    } else if TWTREmailClientEmail != nil { 

     print("Twitter Client Email - \(String(data: TWTREmailClientEmail!, encoding: NSUTF8StringEncoding))") 

     FIRAuth.auth()?.currentUser?.updateEmail("\(TWTREmailClientEmail)", completion: { (updateEmailError: NSError?) in 

      if updateEmailError != nil { 

       print("Set Email from Twitter Error - \(updateEmailError)") 

      } 
     }) 
    } 
}) 

다시, 직물의 문서에 따라, 나는 '이메일'을 포함한 JSON 결과를 얻을 수 있습니다. ": 560,366,005 \"ID_STR \ "\"560,366,005 \ ", \"이름 \ "\"댄 - 옵션 ("{\"아이디 \

트위터 클라이언트 이메일 : 여기 결과입니다 플로리다 기술 \ '20, 애 머스트 \\ 16, 플로리다 기술 \ ', "\", \ "screen_name \": \ "DanLevy114 \", \ "위치 \": \ "버팔로, 뉴욕 \ iOS 개발자 \ ", \"url \ ": \"https : \/\/t.co \/KOtATAEV3X \ ", \"항목 \ ": {\"url \ ": {\"urls \ {\ "url \": \ "https : \/\/t.co \/KOtATAEV3X \", \ "expanded_url \": \ "http : \/\/Instagr.am \/danlevy114 \", \ "display_url \ "설명 \": \ "색인 \": [0,23}}], \ "설명 \": \ "URL \": []}}, \ "protected \ "followers_count \": 292, \ "friends_count \": 196, \ "listing_count \": 4, \ "created_at \": \ "Sun Apr 22 15:20:46 +0000대서양 시간 (캐나다) \ ", \"geo_enabled \ ": 사실, \"즐겨 찾기 _ 개수 ": 1151, \"utc_offset \ ": - 10800 \"시간대 \ ": false ","is_translation_enabled ": false, \"status_count \ ": 1305, \"lang \ ": \ "profile_background_color \": \ "C0DEED \", \ "profile_background_image_url \": \ "http : \/\/pbs.twimg.com \/profile_background_images \/743634202 \ /69dd45bc569542274b017cc25c1e464d.png \", \ "profile_background_image_url_https \" : "https : \/\/pbs.twimg.com \/profile_background_images \/743634202 \ /69dd45bc569542274b017cc25c1e464d.png \", \ "profile_background_tile \": false, \ "profile_image_url \": \ "http : \/\/pbs.twimg.com \/profile_images \/745047852796289024 \ /BWFfrEoI_normal.jpg \ ", \"profile_image_url_https \ ": \"https : \/\/pbs.twimg.com \/profile_images \/745047852796289024 \ /BWFfrEoI_normal.jpg \ ", \"profile_banner_url \ ": \"https : \/\/pbs.twimg.com \/profile_banners \/560366005 \/1466468226 \ ", \"pr \ "profile_sidebar_fill_color \": \ "33FF33 \", \ "profile_text_color \": \ "E05151 \", \ "profile_use_background_image \ false, \ "default_profile_image \": false, \ "follow \": false, \ "follow_request_sent \": false, \ "notifications \": \ "has_extended_profile \": false} ")

트위터 계정으로 로그인했는데 이메일이 나타나지 않았습니다. 내 트위터 계정과 관련된 이메일이 있다는 것을 알고 있습니다. 어떤 아이디어?

답변

0

나는 트위터에서 같은 문제가 있었다. 우선 dev.twitter의 권한을 "읽기 전용"으로 변경합니다.

다음, 트위터로 로그인이 코드를 사용

Twitter.sharedInstance().logInWithCompletion() { session, error in 
     if let session = session { 

      let credential = FIRTwitterAuthProvider.credentialWithToken(session.authToken, secret: session.authTokenSecret) 

      FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in 
       if let error = error { 
        Alert.sharedInstance.showAlert("Error", message: error.localizedDescription) 
        return 
       } 
       //Logged! 
      } 
     } else { 
      Alert.sharedInstance.showAlert("Error", message: error!.localizedDescription) 
     } 
    } 

이 작품 Twitter에 요청하지 않고. Firebase 콘솔의 API 키와 API 암호는 dev.twitter에서 가져옵니다.

+0

감사합니다. –

+0

이메일 주소를 여전히 인쇄 할 수 없습니다. 이메일을 받기 위해해야 ​​할 일이 있습니까? –

관련 문제