【发布时间】:2016-06-27 15:59:22
【问题描述】:
我正在尝试从 Twitter 请求用户的电子邮件地址并将其放入 Firebase。我的应用被 Twitter 列入白名单,并在 apps.twitter.com 门户中激活了它。根据此处的 Fabric 文档,我将这段代码写了出来:
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)")
}
})
}
})
再次,根据 Fabric 的文档,我应该得到一个 JSON 结果,包括“电子邮件”。结果如下:
Twitter 客户电子邮件 - 可选("{\"id\":560366005,\"id_str\":\"560366005\",\"name\":\"丹 Levy\",\"screen_name\":\"DanLevy114\",\"location\":\"Buffalo, NY\",\"description\":\"Florida Tech \'20, Amherst \'16, iOS 开发者\",\"url\":\"https:\/\/t.co\/KOtATAEV3X\",\"entities\":{\"url\":{\"urls\":[{\ "url\":\"https:\/\/t.co\/KOtATAEV3X\",\"expanded_url\":\"http:\/\/Instagr.am\/danlevy114\",\"display_url\" :\"Instagr.am\/danlevy114\",\"indices\":[0,23]}]},\"description\":{\"urls\":[]}},\"protected\" :false,\"followers_count\":292,\"friends_count\":196,\"listed_count\":4,\"created_at\":\"Sun 4 月 22 日 15:20:46 +0000 2012\",\"favourites_count\":1151,\"utc_offset\":-10800,\"time_zone\":\"大西洋 时间 (加拿大)\",\"geo_enabled\":true,\"verified\":false,\"statuses_count\":1305,\"lang\":\"en\",\"contributors_enabled\":false, \"is_translator\":false,\"is_translation_enabled\":false,\"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\/69dd45bc569542274b017\",\"profile_background_image_url_https\" 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\",\ "profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"33FF33\",\"profile_text_color\":\"E05151\",\"pr ofile_use_background_image\":false,\"has_extended_profile\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\ ":false}")
我使用我的 Twitter 帐户登录,但没有出现电子邮件。我知道我有一封与我的 Twitter 帐户相关联的电子邮件。有什么想法吗?
【问题讨论】:
标签: swift firebase firebase-authentication twitter-fabric