iOS Google OAuth, retrieve friends email adresses - ios

I'm trying to get the email addresses of friends of logged in User, from my iOS App using the
[GTLQueryPlus queryForPeopleListWithUserId:#"me"
collection:kGTLPlusCollectionVisible];//kGTLPlusCollectionVisible
I have made authentification scopes like described in the Google Docu:
signIn.scopes = #[
kGTLAuthScopePlusLogin,
kGTLAuthScopePlusMe,
kGTLAuthScopePlusUserinfoEmail,
kGTLAuthScopePlusUserinfoProfile,
#"email",
#"https://www.googleapis.com/auth/plus.profile.emails.read",
#"https://www.googleapis.com/auth/plus.circles.read"
];
Result is, I get the list of friends, but WITHOUT the Email address. As I do not get any error message, I'm really stuck, and have no solution
Can someone help?
Thx.
Patrik

The email scopes only work for the currently authenticated users profile. They don't enable access to the email addresses for other profiles.

Related

AWS Cognito Facebook and Google Plus User login credentials

Folks, am working on, AWS Cognito Facebook and Google Plus login for my iOS app. I can able to SignIn with both FB and G+ credentials and I got Identity ID as a response. Is there any way to get user credentials such as username, email and mobile number. I have tried with user pools but I got null value when I use [self.pool currentUser].username.
I also tried below,
AWSCognito *syncClient = [AWSCognito defaultCognito];
AWSCognitoDataset *dataset = [syncClient openOrCreateDataset:#"myDataSet"];
NSString *userName = [dataset stringForKey:#"name"];
But still getting null as userName. If possible can you please let me know the possible way.
I think you'll have to request for "profile" or other scopes in order to get that.
I recently created a related framework and it has an example of retrieving the user profile information. https://github.com/Thywis/MultiAccountOauth

how to fetch facebook user email id for iOS application?

I have integrated facebook SDK latest version. I followed every steps by facebook docs. I have given permissions as follows
in viewdidload method
loginview = [[FBLoginView alloc] init];
self->loginview.readPermissions = #[#"public_profile", #"user_friends",#"email"];
but for some people accounts, fetching email id, for some people accounts not. I have searched somany forums but not helped me, I have tried changed settings for privacy page for email id access to everyone, but still not geting user email id. I was printed user permissions in my NSLog, suppose if i am getting email id in that time, permissions showing (installed, public profile, email,user_friends), if i am not getting email id that time its showing permissions as (public profile, installed). Really bothering for this from morning onwards. Where should i change code in my application or user facebook profile settings. Please give your valuable suggestions. Thanks

Is there anyway to find the logged in user is the same - Oauth

I am using Oauth gem to login to my web app with facebook, twitter and google accounts. For that I have created a project in each of them and got app id and secret id. I want a single entry in my database even the user logged in with the same mail id in all the three. We are storing the following info in database(email, name, provider, uid). The problem is twitter does not provide mail id. So I have planned to generate mail id from nick name.
user.rb
//for facebook and google
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
//for twitter
user = User.create(name: auth['info']['nickname'],
provider: auth.provider,
uid: auth.uid,
email: auth['info']['nickname'] + '#twitter.com',
password:Devise.friendly_token[0,20],
)
For example
I log in with mail id example#gmail.com in facebook, twitter and google. But in my db it creates two entries
11 | example#gmail.com // for facebook and google
12 | nickname#twitter.com // for twitter
I don't this behavior. Is it any other possible ways to find the logged in user is the same person?? I want just a single entry. Kindly suggest me any better ways if possible.
As far as I know, this is not easily possible at present. If there is no information in common between twitter and the other services, how can you automatically associate them? Also, if you make up an #twitter.com email address for people logging in via twitter, then you've got an invalid/unusable email address in your database (unless that person is an employee of twitter and happens to have a twitter name the same as the local part of their email address - but worse, if someone happens to have a twitter name matching the local part of an email address of a twitter employee but isn't that employee, you've got a valid email address but the user on your site doesn't own it - I don't know if this is possible offhand, and if you are using :confirmable they wouldn't confirm the email address).
You've got at least a couple of options:
When the person has logged in via twitter and returns to your site, ask for their email address so you can check if they're already registered with that.
Generate some sort of fake unique email address for people coming from twitter that you can tell is fake later (so you never try to confirm it or send any other email to it) or allow blank email addresses (perhaps a bit tricky for devise because it's generally assumed that an email address is defined and exists for each user). Then allow people to merge arbitrary accounts on your site by logging in using one of them and then entering the credentials for the other one (the credentials would need to be them logging in via the external service, because they won't know your auto-generated Devise.friendly_token password unless the other account was one registered directly with your site, if you support that). You then have to deal with merging whatever is associated with those two accounts, which might be tricky depending on what you have associated with a user in your model.
For a comprehensive system, you might want to allow people to merge arbitrary accounts anyway, for the situation where the same person is registered with different email addresses on google and Facebook for example.
Also, note that you won't necessarily get an email address back from Facebook for someone logging in via Facebook. People can register with Facebook with just a phone number, so in that case Facebook doesn't have their email address.

Requesting user information and Friends from Facebook

I am looking to combine a call to Facebook Graph API. I would like to collect both the friends and profile information in one go.
I have also raised a separate question issue here - Facebook SDK collecting user information and friends
What is the correct/easiest way to create a Facebook Graph request for both these parts?
The user is logged in with this permission array:
NSArray *permissionsArray = #[ #"user_about_me", #"user_birthday", #"user_location", #"email"];
I am then trying to create a graph connection to get information 'such as' username, email, friend list. Ideally I want to do this in one FBRequest, rather than separate FBRequestConnection(s). How can I accomplish this? I have looked through the Facebook SDK information and cannot see how to do this, how can I find out more information on this?
You can get all of this information in one API call to:
/me?fields=id,username,email,friends
I'm not sure of the syntax for iOS.
If you want more data about your friends, you can specify fields through field expansion, like this:
/me?fields=id,username,email,friends.fields(id,name,username,birthday)

Is there a way to get a user's email ID after verifying his/her Twitter identity using OAuth?

I am new to OAuth and have been playing around with the Twitter API. I am able to fetch the credentials of a user after authentication by making a request to http://api.twitter.com/1/account/verify_credentials.xml. The response contains the user id, screen name etc. but not the email ID.
Is it possible at all to retrieve the email ID of the user?
Update
I believe Facebook provides this information if you specifically request for extended permissions. Is there something similar for Twitter?
The user's email address can not be retrieved via the API. This is a deliberate design decision by the API team.
UPDATE 2015.08.18:
It is possible to request an email address from users, but it requires your app to be whitelisted. See https://dev.twitter.com/rest/reference/get/account/verify_credentials for details of the API call and this form to request whitelisting of your app.
For OutsourceFactor, which is written in Python / Django, I get the username via oAuth1, then construct an email as "username#twitter.com" which is guaranteed to be unique throughout twitter. Then I hash it to get a nice UUID to be used and associated with my local user account. Same thing for Yahoo. Google and Facebook use oAuth2 and they give me the email address on request which is nice.
To ensure multiple social associations with a single account, I allow social account associations ONLY after the user has locally created an account and is logged in.
So, you have to create an account first (local account), then you can use any of the social oAuth providers to ease your future logins. This is the best bang for the buck for my site.
Anyways, you get some unique form of ID from twitter. So just use it. You can ask for an email address later or before the association.
Email address is obfuscated by Twitter in their OAuth responses. Which always have been a great issue for people wanting to include a "Register with Twitter" function.
More recently (early 2015), Twitter have added email address support through a second service call, but under certain, abused, conditions.
https://dev.twitter.com/rest/reference/get/account/verify_credentials
So now it is possible, but my opinion is to continue to implement an OAuth every-provider-but-twitter single sign on. They must be boycotted until they act normally, i mean like every single other OAuth provider.
In Android using Fabric, I request the user's email address like this:
TwitterAuthClient authClient = new TwitterAuthClient();
authClient.requestEmail(session, new Callback<String>() {
#Override
public void success(Result<String> result) {
// Do something with the result, which provides the email address
}
#Override
public void failure(TwitterException exception) {
// Do something on failure
}
});
See http://docs.fabric.io/android/twitter/request-user-email-address.html
In my case every time I get the response I got a unique authentication id for every user and its same for that user every time. So I used that id to create a email like unique_id#twitter.com and check if that's already on my site ( for first time it is not ) and then register the user. Then if he logins second time I just again create the email and check if its already on there. By this I don't have to make him create a local account first and can identify him to login.
Here is the example how to get twitter user email in Laravel, and on coditty.com you can find the full example using Angular+Laravel
// get token secret from db
$token = TwitterTokens::where('oauth_token', $request->input('oauth_token'))->first();
// open twitter connection
$connection = new \Abraham\TwitterOAuth\TwitterOAuth(
$this->twitter_consumer_key,
$this->twitter_secret,
$request->input('oauth_token'),
$token->oauth_token_secret// twitter secret from DB
);
// get acces token
$access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $request->input('oauth_verifier')]);
// new TwitterOAuth instance to get email
$twitterOAuth = new \Abraham\TwitterOAuth\TwitterOAuth( $this->twitter_consumer_key, $this->twitter_secret, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
// Let's get the user's info with email
$twitterUser = $twitterOAuth->get('account/verify_credentials', ['include_entities' => 'false','include_email'=>'true','skip_status'=>'true',]);
// output user object from twitter in your Log file
Log::info(['user'=>$twitterUser]);
Who said it's not possible ???
I have gotten in my iOS App after whitelisting the App.
Check my answer here.
Add this code!
$params = array('include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true');
`$data = $connection->get('account/verify_credentials', $params); // get the data`
// getting twitter user profile details
$twt_id = $data->id; //twitter user id
$twt_email = $data->email; //twitter user email
Checkout full procedure here.
Who says you cant get users email, the “Request email addresses from users” checkbox is available under the app permissions on apps.twitter.com. Privacy Policy URL and Terms of Service URL fields must be completed in the app settings in order for email address access to function. If enabled, users will be informed via the oauth/authorize dialog that your app can access their email address.

Resources