How to get email from twitter by fabric in iOS 9? [duplicate] - ios

I have integrated twitter kit in my ios app by following https://dev.twitter.com/twitter-kit/ios/configure this. I could sign-in after authentication and see my twitter name easily but now i want to retrieve my email address so i used TWTRShareEmailViewController which presents user a share email view which returns null. I went through the docs where they mentioned about my app to be whitelisted for requesting email permission and said to fill up this form https://support.twitter.com/forms/platform am not getting what to do next? how to get i user email permission exactly? Suggest any help. Thanks in advance.

I didn't find a specific form to ask to be whitelisted neither. I went on their form link https://support.twitter.com/forms/platform and I checked the "I have an API policy question not covered by these points" option. They responded a few days after and asked me more information about the application and its app ID. I'm actually waiting for their answer.
EDIT:
So after several (a lot) emails with support#fabric.io and a few bugs I finally got whitelisted. But the option is currently unavailable with Fabric so you'll have to create a Twitter app on apps.twitter.com. Just send a mail with your app ID or your keys. They'll probably ask you a quick description of your app and it shouldn't take so much time to be whitelisted. Good luck!

After having a conversation with sdk-feedback#twitter.com, I got my App whitelisted. Here is the story:
Send mail to sdk-feedback#twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App. Mention in mail that you want to access user email address inside your App.
They will review your App and reply to you within 2-3 business days.
Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:
On the 'Settings' tab, add a terms of service and privacy policy URL
On the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.
It's time to code:
-(void)requestUserEmail
{
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
} else {
// Handle user not signed in (e.g. attempt to log in or show an alert)
}
}
Hope it helps !!!

Send email to sdk-feedback#twitter.com to whitelist your twitter login app first.
Swift 3.0 Code with fabric
#IBAction func btnTwitterAction(_ sender: AnyObject) {
Twitter.sharedInstance().logIn { (session, error) in
if session != nil {
print("signed in as \(session!.userName)");
let client = TWTRAPIClient.withCurrentUser()
let request = client.urlRequest(withMethod: "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) {
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)")
}
}
} else {
NSLog("Login error: %#", error!.localizedDescription);
}
}
}

How to get email id in twitter ?
Step 1 : got to https://apps.twitter.com/app/
Step 2 : click on ur app > click on permission tab .
Step 3 : here check the email box

I've faced the same issue recently
Here is what you should try if you are using new twitter kit
Go to
https://apps.twitter.com/
Select permissions tab
Set it to Read Only
Code :
Twitter.sharedInstance().logIn(withMethods: [.webBased,.systemAccounts,.all]) {(session, error) -> Void in
if (session != nil) {
print("signed in as \(session?.userName)");
let client = TWTRAPIClient(userID: session?.userName)
client.loadUser(withID: (session?.userID)!, completion: { (user, error) in
let twitterClient = TWTRAPIClient.withCurrentUser()
let request = twitterClient.urlRequest(withMethod: "GET",
url: "https://api.twitter.com/1.1/account/verify_credentials.json",
parameters: ["include_email": "true", "skip_status": "true"],
error: nil)
twitterClient.sendTwitterRequest(request) { response, data, connectionError in
print(data!)
let s :String = String(data: data! as Data, encoding: String.Encoding.utf8)!
//
// let json = try JSONSerialization.jsonObject(with: responseData as Data, options: JSONSerialization.ReadingOptions.mutableLeaves) as? [String:AnyObject]
//
Twitter.sharedInstance().sessionStore.logOutUserID((session?.userID)!)
if let data = s.data(using: String.Encoding.utf8) {
do {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
print(json!)
} catch {
print("Something went wrong")
}
}
}
})
} else {
}

Related

Firebase Email Verification Redirect Url

I incorporated Firebase's email verification for my iOS mobile app and am trying to resolve the following issues:
The length of the redirect url appears extremely long. It looks like it repeats itself.
https://app.page.link?link=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail#gmail.com%26lang%3Den&ibi=com.app.app&ifl=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail#gmail.com%26lang%3Den
When I set handleCodeInApp equal to true, and am redirected back to the app when I click on the redirect url, the user's email is not verified. Whereas when I set it to false and go through Firebase's provided web widget, it does get verified. Wasn't able to find documentation that outlined handling the former in swift...
Any thoughts are appreciated.
func sendActivationEmail(_ user: User) {
let actionCodeSettings = ActionCodeSettings.init()
let redirectUrl = String(format: "https://www.app.com/?verifyemail=%#", user.email!)
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.url = URL(string: redirectUrl)
actionCodeSettings.setIOSBundleID("com.app.app")
Auth.auth().currentUser?.sendEmailVerification(with: actionCodeSettings) { error in
guard error == nil else {
AlertController.showAlert(self, title: "Send Error", message: error!.localizedDescription)
return
}
}
}
Make sure you're verifying the oobCode that is part of the callback URL.
Auth.auth().applyActionCode(oobCode!, completion: { (err) in
if err == nil {
// reload the current user
}
})
Once you have done that, try reloading the the user's profile from the server after verifying the email.
Auth.auth().currentUser?.reload(completion: {
(error) in
if(Auth.auth().currentUser?.isEmailVerified)! {
print("email verified")
} else {
print("email NOT verified")
}
})

LinkedIn login with custom token ( ERROR_INVALID_CUSTOM_TOKEN )

I am trying to login with LinkedIn using the native app and the LinkedIn SDK. So far I can login using the web if the LinkedIn app is not installed. I can also login with LinkedIn and get a token in return. But when I try to authenticate with Firebase I get this error:
Optional(Error Domain=FIRAuthErrorDomain Code=17000 "The custom token
format is incorrect. Please check the documentation." UserInfo=
{NSLocalizedDescription=The custom token format is incorrect. Please
check the documentation., error_name=ERROR_INVALID_CUSTOM_TOKEN})
This is my code:
// App installed
let permissions = [LISDK_BASIC_PROFILE_PERMISSION,LISDK_EMAILADDRESS_PERMISSION]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: { (returnState) -> Void in
LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,public-profile-url,industry,positions,location)?format=json", success: { (response) -> Void in
if let data = response?.data.data(using: String.Encoding.utf8) {
if let dictResponse = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers){
let token = LISDKSessionManager.sharedInstance().session.accessToken.accessTokenValue
Auth.auth().signIn(withCustomToken: token! ) { (user, error) in
print(user!)
print(error!)
}
}
}
}, error: { (error) -> Void in
print("LINKEDIN error\(String(describing: error))")
})
}) { (error) -> Void in
print("error login linkedin")
}
The token I am sending to Firebase is a String, so that should be okay. I must be missing something. But what ?
The problem was my misunderstanding. I thought I could use the Linkedin token directly. It has to go to a webservice that uses the Firebase admin user to generate the token.

How to tag a facebook page in FBSDK for iOS

While using the FBSDK for iOS, I am trying to attach/tag a relevant facebook page. Any pointers to their docs? I looked up some info on message_tags parameter but not sure how to use it.
let shareParams = ["message":"Check out this page #PAGE_NAME"]
let fbRequest = FBSDKGraphRequest.init(graphPath: "me/feed", parameters: shareParams, HTTPMethod: "POST")
fbRequest.startWithCompletionHandler { (connection :FBSDKGraphRequestConnection!, result, error) -> Void in
if let responseError = error {
if responseError.domain == FacebookSharerErrorDomain.FacebookAPIError.rawValue {
self.handleFacebookAPIError(responseError)
} else {
Error("Unable to share")
}
} else {
Success("Shared to Facebook")
}
}
I think this is what you looking for (if anchor didn't work refresh page. or search "Mentioning Friends or Pages" section).
Also look at taggable_friends endpoint.

how to request permission to retrieve user's email using twitter kit version 1.2.0 in ios8?

I have integrated twitter kit in my ios app by following https://dev.twitter.com/twitter-kit/ios/configure this. I could sign-in after authentication and see my twitter name easily but now i want to retrieve my email address so i used TWTRShareEmailViewController which presents user a share email view which returns null. I went through the docs where they mentioned about my app to be whitelisted for requesting email permission and said to fill up this form https://support.twitter.com/forms/platform am not getting what to do next? how to get i user email permission exactly? Suggest any help. Thanks in advance.
I didn't find a specific form to ask to be whitelisted neither. I went on their form link https://support.twitter.com/forms/platform and I checked the "I have an API policy question not covered by these points" option. They responded a few days after and asked me more information about the application and its app ID. I'm actually waiting for their answer.
EDIT:
So after several (a lot) emails with support#fabric.io and a few bugs I finally got whitelisted. But the option is currently unavailable with Fabric so you'll have to create a Twitter app on apps.twitter.com. Just send a mail with your app ID or your keys. They'll probably ask you a quick description of your app and it shouldn't take so much time to be whitelisted. Good luck!
After having a conversation with sdk-feedback#twitter.com, I got my App whitelisted. Here is the story:
Send mail to sdk-feedback#twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App. Mention in mail that you want to access user email address inside your App.
They will review your App and reply to you within 2-3 business days.
Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:
On the 'Settings' tab, add a terms of service and privacy policy URL
On the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.
It's time to code:
-(void)requestUserEmail
{
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
} else {
// Handle user not signed in (e.g. attempt to log in or show an alert)
}
}
Hope it helps !!!
Send email to sdk-feedback#twitter.com to whitelist your twitter login app first.
Swift 3.0 Code with fabric
#IBAction func btnTwitterAction(_ sender: AnyObject) {
Twitter.sharedInstance().logIn { (session, error) in
if session != nil {
print("signed in as \(session!.userName)");
let client = TWTRAPIClient.withCurrentUser()
let request = client.urlRequest(withMethod: "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) {
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)")
}
}
} else {
NSLog("Login error: %#", error!.localizedDescription);
}
}
}
How to get email id in twitter ?
Step 1 : got to https://apps.twitter.com/app/
Step 2 : click on ur app > click on permission tab .
Step 3 : here check the email box
I've faced the same issue recently
Here is what you should try if you are using new twitter kit
Go to
https://apps.twitter.com/
Select permissions tab
Set it to Read Only
Code :
Twitter.sharedInstance().logIn(withMethods: [.webBased,.systemAccounts,.all]) {(session, error) -> Void in
if (session != nil) {
print("signed in as \(session?.userName)");
let client = TWTRAPIClient(userID: session?.userName)
client.loadUser(withID: (session?.userID)!, completion: { (user, error) in
let twitterClient = TWTRAPIClient.withCurrentUser()
let request = twitterClient.urlRequest(withMethod: "GET",
url: "https://api.twitter.com/1.1/account/verify_credentials.json",
parameters: ["include_email": "true", "skip_status": "true"],
error: nil)
twitterClient.sendTwitterRequest(request) { response, data, connectionError in
print(data!)
let s :String = String(data: data! as Data, encoding: String.Encoding.utf8)!
//
// let json = try JSONSerialization.jsonObject(with: responseData as Data, options: JSONSerialization.ReadingOptions.mutableLeaves) as? [String:AnyObject]
//
Twitter.sharedInstance().sessionStore.logOutUserID((session?.userID)!)
if let data = s.data(using: String.Encoding.utf8) {
do {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
print(json!)
} catch {
print("Something went wrong")
}
}
}
})
} else {
}

How to get user email address via Twitter API in iOS?

I have tried multiple SDK's but was unable to get an email ID from any of the resources. I have tried FHSTwitterEngine for this purpose but I didn't get the solution.
FHSTwitterEngine *twitterEngine = [FHSTwitterEngine sharedEngine];
NSString *username = [twitterEngine loggedInUsername]; //self.engine.loggedInUsername;
NSString *key = [twitterEngine accessToken].key;
NSString *secrete = [twitterEngine accessToken].secret;
if (username.length > 0)
{
NSDictionary *userProfile = [[FHSTwitterEngine sharedEngine] getProfileUsername:username];
NSLog(#"userProfile: %#", userProfile);
EDIT
After Twitter has updated APIs, Now user can get Email using TWTRShareEmailViewController class.
// Objective-C
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController* shareEmailViewController = [[TWTRShareEmailViewController alloc] initWithCompletion:^(NSString* email, NSError* error) {
NSLog(#"Email %#, Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController animated:YES completion:nil];
} else {
// TODO: Handle user not signed in (e.g. attempt to log in or show an alert)
}
// Swift
if Twitter.sharedInstance().session {
let shareEmailViewController = TWTRShareEmailViewController() { email, error in
println("Email \(email), Error: \(error)")
}
self.presentViewController(shareEmailViewController, animated: true, completion: nil)
} else {
// TODO: Handle user not signed in (e.g. attempt to log in or show an alert)
}
NOTES:
Even if the user grants access to her email address, it is not guaranteed you will get an email address. For example, if someone signed up for Twitter with a phone number instead of an email address, the email field may be empty. When this happens, the completion block will pass an error because there is no email address available.
Twitter Dev Ref
PAST
There is NO way you can get email address of a twitter user.
The Twitter API does not provide the user's email address as part of the OAuth token negotiation process nor does it offer other means to obtain it.
Twitter Doc.
You will have to use Twitter framework. Twitter has provided a beautiful framework for that, you just have to integrate it in your app.
To get user email address, your application should be whitelisted. Here is the link. Go to use this form. You can either send mail to sdk-feedback#twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App etc..They will respond within 2-3 working days.
Here is the story how I got whitelisted by conversation with Twitter support team:
Send mail to sdk-feedback#twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App. Mention in mail that you want to access user email adress inside your App.
They will review your App and reply to you withing 2-3 business days.
Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:
On the 'Settings' tab, add a terms of service and privacy policy URL
On the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.
Put your hands on code
Use of Twitter framework:
Get user email address
-(void)requestUserEmail
{
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
} else {
// Handle user not signed in (e.g. attempt to log in or show an alert)
}
}
Get user profile
-(void)usersShow:(NSString *)userID
{
NSString *statusesShowEndpoint = #"https://api.twitter.com/1.1/users/show.json";
NSDictionary *params = #{#"user_id": userID};
NSError *clientError;
NSURLRequest *request = [[[Twitter sharedInstance] APIClient]
URLRequestWithMethod:#"GET"
URL:statusesShowEndpoint
parameters:params
error:&clientError];
if (request) {
[[[Twitter sharedInstance] APIClient]
sendTwitterRequest:request
completion:^(NSURLResponse *response,
NSData *data,
NSError *connectionError) {
if (data) {
// handle the response data e.g.
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
NSLog(#"%#",[json description]);
}
else {
NSLog(#"Error code: %ld | Error description: %#", (long)[connectionError code], [connectionError localizedDescription]);
}
}];
}
else {
NSLog(#"Error: %#", clientError);
}
}
Hope it helps !!!
If you'd like a user's email address, you'll need to ask a user for it within the confines of your own application and service. The Twitter API does not provide the user's email address as part of the OAuth token negotiation process nor does it offer other means to obtain it.
In Swift 4.2 and Xcode 10.1
It's getting email also.
import TwitterKit
#IBAction func onClickTwitterSignin(_ sender: UIButton) {
TWTRTwitter.sharedInstance().logIn { (session, error) in
if (session != nil) {
let name = session?.userName ?? ""
print(name)
print(session?.userID ?? "")
print(session?.authToken ?? "")
print(session?.authTokenSecret ?? "")
let client = TWTRAPIClient.withCurrentUser()
client.requestEmail { email, error in
if (email != nil) {
let recivedEmailID = email ?? ""
print(recivedEmailID)
}else {
print("error--: \(String(describing: error?.localizedDescription))");
}
}
let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "SVC") as! SecondViewController
self.navigationController?.pushViewController(storyboard, animated: true)
}else {
print("error: \(String(describing: error?.localizedDescription))");
}
}
}
Swift 3-4
#IBAction func btnTwitterAction(_ sender: Any) {
TWTRTwitter.sharedInstance().logIn(completion: { (session, error) in
if (session != nil) {
print("signed in as \(String(describing: session?.userName))");
if let mySession = session{
let client = TWTRAPIClient.withCurrentUser()
//To get User name and email
client.requestEmail { email, error in
if (email != nil) {
print("signed in as \(String(describing: session?.userName))");
let firstName = session?.userName ?? "" // received first name
let lastName = session?.userName ?? "" // received last name
let recivedEmailID = email ?? "" // received email
}else {
print("error: \(String(describing: error?.localizedDescription))");
}
}
//To get user profile picture
client.loadUser(withID: session?.userID, completion: { (userData, error) in
if (userData != nil) {
let fullName = userData.name //Full Name
let userProfileImage = userData.profileImageLargeURL //User Profile Image
let userTwitterProfileUrl = userData?.profileURL // User TwitterProfileUrl
}
})
}
} else {
print("error: \(error?.localizedDescription)");
}
})
}

Resources