Can you get your Twitter email using the API? - ios

I am developing a iOS App and I have login with Facebook, LinkedIn, Google+ and Twitter.
All of them let me read my email from my profile using API, EXCEPT Twitter.
Is there any way to get my email?
If not, is there in twitter a "internal email", a generated email like in facebook (someone#facebook.com)?
The reason is that I use email as identifier (primary key) for users in my database.

No, email address are not available via the Twitter API: https://dev.twitter.com/discussions/1737
Nor is there any "internal email" available, you will have to use the twitter username and ask the user fro there e-mail address.

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 !!!

Related

Unable to fetch user's email from twitter using twitter fabric iOS framework

I am trying my hands on new fabric twitter kit for iOS.
After signing in we can ask user to allow access for the email id and if it allows then returns email of the logged in user but it giving me error.
Email (null), Error: Error Domain=NSURLErrorDomain Code=-1001
"The request timed out." UserInfo=0x7fdd314f1c30
{NSUnderlyingError=0x7fdd314d9aa0 "The request timed out.",
NSErrorFailingURLStringKey=https://api.twitter.com/1.1/account/verify_cre
dentials.json?skip_status=true&include_email=true,
NSErrorFailingURLKey=https://api.twitter.com/1.1/account/verify_credentia
ls.json?skip_status=true&include_email=true,
NSLocalizedDescription=The request timed out.}
And here is my code that i've tried from their doc.
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)
}
Is anything wrong in my code? Please help me.
I can post my status and media to twitter but can't get email Id.
Can anyone please help me in this problem? I'm also new to development.
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 !!!

Get user profile details (especially email address) from Twitter in iOS

I am aiming to get a user's details based on his/her Twitter account. Now first of all, let me explain what I want to do.
In my case, user will be presented an option to Sign-up with Twitter account. So, based on user's Twitter account, I want to be able to get user details (e.g. email-id, name, profile picture, birth date, gender etc..) and save those details in database. Now, many people will probably suggest me to use ACAccount and ACAccountStore, a class that provides an interface for accessing, manipulating, and storing accounts. But in my case, I want to sign up user, even if user has not configured an account for Twitter in iOS Settings App. I want user to navigate to login screen of Twitter (in Safari or in App itself, or using any other alternative).
I have also referred the documentation of Twitter having API list here. But I am a lot confused how user should be presented a login screen to log into the Twitter account and how I will get profile information. Should I use UIWebView, or redirect user to Safari or adopt another way for that ?
Finally, after having a long 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.
Put your hands on code:
Agree with statement of Vizllx: "Twitter has provided a beautiful framework for that, you just have to integrate it in your app."
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 !!!
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
Twitter has provided a beautiful framework for that, you just have to integrate it in your app.
https://dev.twitter.com/twitter-kit/ios
It has a simple Login Method:-
// Objective-C
TWTRLogInButton* logInButton = [TWTRLogInButton
buttonWithLogInCompletion:
^(TWTRSession* session, NSError* error) {
if (session) {
NSLog(#"signed in as %#", [session userName]);
} else {
NSLog(#"error: %#", [error localizedDescription]);
}
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton];
This is the process to get user profile information:-
/* Get user info */
[[[Twitter sharedInstance] APIClient] loadUserWithID:[session userID]
completion:^(TWTRUser *user,
NSError *error)
{
// handle the response or error
if (![error isEqual:nil]) {
NSLog(#"Twitter info -> user = %# ",user);
NSString *urlString = [[NSString alloc]initWithString:user.profileImageLargeURL];
NSURL *url = [[NSURL alloc]initWithString:urlString];
NSData *pullTwitterPP = [[NSData alloc]initWithContentsOfURL:url];
UIImage *profImage = [UIImage imageWithData:pullTwitterPP];
} else {
NSLog(#"Twitter error getting profile : %#", [error localizedDescription]);
}
}];
I think rest you can find from Twitter Kit Tutorial, it also allows to request a user’s email, by calling the TwitterAuthClient#requestEmail method, passing in a valid TwitterSession and Callback.
In Twitter you can get user_name and user_id only. It is that much secure that you can't fetch email id, birth date, gender etc.., compare to Facebook, Twitter is very confidential for supplying the data.
need ref: link1.
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))");
}
}
//To get profile image url and screen name
let twitterClient = TWTRAPIClient(userID: session?.userID)
twitterClient.loadUser(withID: session?.userID ?? "") {(user, error) in
print(user?.profileImageURL ?? "")
print(user?.profileImageLargeURL ?? "")
print(user?.screenName ?? "")
}
let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "SVC") as! SecondViewController
self.navigationController?.pushViewController(storyboard, animated: true)
}else {
print("error: \(String(describing: error?.localizedDescription))");
}
}
}
Follow the Harshil Kotecha answer.
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
If you want to logout
let store = TWTRTwitter.sharedInstance().sessionStore
if let userID = store.session()?.userID {
print(store.session()?.userID ?? "")
store.logOutUserID(userID)
print(store.session()?.userID ?? "")
self.navigationController?.popToRootViewController(animated: true)
}

"Error occurred" facebook login in ios application

i have integrate the facebook sdk for post something on facebook.Its working for only single facebook-id which is used for integrating facebook it in my application, not working for other.
this is my code
-(IBAction)postOnFacebook:(id)sender {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Sharing Tutorial", #"name",#"Build great social apps and get more installs.", #"caption", #"Allow your users to share stories on Facebook from your app using the iOS SDK.", #"description",#"https://developers.facebook.com/docs/ios/share/", #"link",#"http://i.imgur.com/g3Qc1HN.png", #"picture",nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User cancelled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User cancelled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];
}
// A function for parsing URL parameters returned by the Feed Dialog.
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:#"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:#"="];
NSString *val =
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}
this meth
Error come when i use another id for login
You are using the publish_action permission which can be made availaible to all users only after approval from facebook.
Currently you might have created the facebook app in your account and with that account id you will be able to post to facebook. This is because of the reason that facebook gives all the permissions to users who are added as Developers/Testers in the App Dashboard.
You can add people to your app as Testers/Developers by following the steps as described below
You'll need to be an admin to give someone a role on your Page. If the person is your Facebook friend:
Go to your Page and tap More.
Tap Edit Settings > Page Roles.
Tap Add Person to Page. You may need to enter your password to continue.
Begin typing a friend's name and tap their name from the list that appears.
Tap to choose a role > Add.
If the person isn't your Facebook friend, you can log into Facebook from a computer and add them by entering their email address.
Depending on their settings, the person may receive a notification or an email when you give them a role.
These users who are added will have all the permission that you are requesting.
If you want the permissions to be availaible to everyone, your facebook app should be approved and for that you have to submit your app to facebook for review. The guidelines for facebook app submision can be found from the following link
https://developers.facebook.com/docs/apps/review
Hope this helps you
I'm not sure if I understood your question.
But, for what I'm seeing. If you have created app at facebook (to integrate with your iOS app) you have to use the facebook app ID only, presented at Facebook.
Or, if this error is because you are trying to login with another facebook account. This is happening probably because you did not publish your app yet (facebook app). So it's not available to everyone, but its ok because you probably don't want to make it available right now. So you just need to go to the left menu at Roles in your facebook app page and add test users (the account that you're trying to login) or add as administrator.

Showing "Your application may not have access to email addresses" when try to get email address of twitter user using Fabric Twitter SDK

I'd like to request the user's Twitter mail. On https://dev.twitter.com/twitter-kit/ios/request-email
Code is:
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController* shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString* email, NSError* error) {
if (error)
{
NSLog(#"Error %#",error.localizedDescription);
}else
{
NSLog(#"Email %#",email);
}
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
}
use this link https://support.twitter.com/forms/platform to submit a request for your app to be granted for user's email address. Choose any one of the the options and fill all the information.
Here is the example after you get permission:
check on this URL : https://apps.twitter.com/app/APP_ID/permissions

Facebook App Request not being sent in iOS

I have my app set up to send facebook app requests. I get the popup screen to pick friends and when I click on send button, the popup disappears. And I get a request ID printed out in the console as well.
Although the friends that I have selected to send the request has not received the app request.
I have facebook sdk 3.1 which works well with other activities such as posting to user's walls etc.
Possible duplicates:
Facebook iOS SDK - Sending a facebook user an app request
How to Send App request to facebook friends through facebook iOS sdk?
The answer on the second link provides a step by step procedure on how to fix this.
Make sure your facebook app id is same in both developer page and info in xcode next, enable sandbox mode and must fill canvas url [under app on facebook category] in developer page.
NSString *facebookID = #"Your friend facebook id";
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObject:facebookID forKey:#"to"];
NSString *message = #"SOME_MESSAGE";
NSString *title = #"TITLE";
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:message
title:title
parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
}
else
{
NSLog(#"Request Sent. %#", params);
}
}}];

Resources