Missing e-mail when using ParseUI with Facebook login/signup - ios

I'm using the the PFLogInViewController of the ParseUI framework. I have two questions related to emails with regards to Facebook Login within the framework:
1) When signing up via Facebook, I see that the email field of my new user is 'undefined.' How can I obtain the user's email address?
2) If I am able to obtain the email address, does parse's application setting of 'emailVerified' still send a verification email to the user upon Facebook signup? If not, how can this be done?
Thanks.

In order to read the user's email address you'll need to add email to your array of Facebook permissions you're requesting. Look at the Parse tutorial on this https://www.parse.com/tutorials/login-and-signup-views#properties
In your case, you'll want to add #"email" like this:
[logInViewController setFacebookPermissions:[NSArray arrayWithObjects:#"friends_about_me", #"email", nil]];
Then when you are requesting the user information from Facebook, you will be able to access the user's email address:
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Now you can access user's email
NSString *email = result[#"email"];
if (email) {
// Save it to your email field in Parse
}
}
}];
Regarding part 2 of your question, I'm not as familiar with the email validation functionality that Parse supports, but looking at this (admittedly old) response https://www.parse.com/questions/email-verification-emails-going-out-to-facebook-users it appears that Parse will validate email addresses even when the user logs in with Facebook.

Related

FaceBook Messenger SDK How to get the user's name

I am working on messenger app, mostly by looking at the docs here
The only gotcha is how to pass the user information to the person you are sharing the content with?
From docs it seems that FBSDKMessengerURLHandlerReplyContext may contain userID
NSSet *userIds = context.userIDs
Yet, how can i use the userID to get the user information? Or is it even the right way to fetch user info?
It seems like this task is doable. This game does that
It can tell the user info in first screen, without actually asking user to login.
Any Idea or help on how to make it happen?
If the user IDs are from users that already authenticate in your app, it can be achieved using graph API, like they say on facebook Docs:
User IDs can be used with the Facebook SDK and Graph API
(https://developers.facebook.com/docs/graph-api) to query names,
photos, and other data. This will only contain IDs of users that have
also logged into your app via their Facebook account.
Here some code on how to use the graph API with user id. You can make a call as it follows:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:#"/%#", {userID-goes-here}]
parameters:#{#"fields":#"name,id,picture,gender,birthday,email"}
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (!error){
NSLog(#"result: %#",result);
}
}];
the result of this request looks like this:
{
birthday = "06/24/1981";
email = "XXXXXX#hotmail.com";
gender = male;
id = 67XXXXX39;
name = "Adriano Spadoni";
picture = {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-prof... ...jpg";
};
};
}
Just remember, some fields maybe be null.
You probably will need to do a loop requesting user by user I'm afraid, if someone knows how to ask a patch of users at the same time, please show us how.
BUT
If you want to get info from users that NOT installed your app yet, you need to:
FBSDKGraphRequest(graphPath: "me/taggable_friends", parameters: ["fields":"installed,id,name,picture.width(1000)"]).startWithCompletionHandler({ (connection, result, err) -> Void in
if err == nil {
print(result)
}
})
You can't get the username anymore because /me/username is no longer available.
Source: https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
If you want to detect returning users, use the (App Scoped) ID instead.

Get the relationship status of user's Facebook friends

This is what I'm using now:
if ([FBSDKAccessToken currentAccessToken]) {
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me?fields=id,name,friends{relationship_status}"
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Result: %#", result);
}];
}
but the result contains an empty list of friends. I guess this list contains the friends that have installed this same app.
Using the Graph Tool Explorer I can get this list
GET /v2.3/me?fields=id,name,friends{relationship_status,gender}
How can I get this list in iOS?
Permissions that I'm calling are:
loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends"];
***** UPDATE *****
Ok, I've read the confirmation: "Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app."
Has anyone used taggable_friends or something like that to get the list of friends making more requests later to get the information about each and every friend? Is this something Facebook can reject when submitting the app?
That's not possible, because all friends_* permissions have been removed. Please don't waste your time trying to find a workaround.
See
https://developers.facebook.com/docs/apps/changelog#v2_0
All friends_* permissions have been removed.

Parameter for like count with facebook api V2.3

I am using this line of code for getting count of likes on facebook post
NSString *postId = #"1234567890_1234567890";
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:postId,#"ObjectId",nil];
NSString * str = (NSString *) [[[FBSDKGraphRequest alloc] initWithGraphPath:#"/{object-id}/likes"
parameters:photosParams
HTTPMethod:#"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if ([error.userInfo[FBSDKGraphRequestErrorGraphErrorCode] isEqual:#200]) {
NSLog(#"%#",[error localizedDescription]);
}
}];
but I am getting error of unsupported url, any one have Idea what parameter I use to get result. I am using updated version of facebook api
As
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
states, you need
The same permissions required to view the parent object are required to view likes on that object.
That means that the permission setting for Posts (https://developers.facebook.com/docs/graph-api/reference/v2.3/post) apply:
For page posts, public posts by the page are retrievable with any valid access token. Posts by people on the page, posts by people which mention the page, or targeted page posts (by language or geography, for example) may require a user or page token.
A user access token with read_stream or user_posts permission for any other posts
Are you sure you're adding an Access Token to your request?
You can request multiple posts at once like this:
/?ids={object_id1},{object_id2}&fields=id,created_time,likes.summary(true).limit(0)

Cant get FBGraphUser email

I use Facebook login with my app. (Facebook iOS SDK version 3.11.1)
I ask for "email" permission:
NSArray *permissions = [NSArray arrayWithObjects: #"basic_info", #"email", nil];
Most of the time, I do get the user's email like that:
NSString *email = [user objectForKey:#"email"];
//user is (NSDictionary<FBGraphUser> *)
Sometimes I just don't. (I can see that the NSDictionary is not including email).
I am using this fix so the app won't terminate when i use email later and its nil:
NSString *email = [user objectForKey:#"email"] ? [user objectForKey:#"email"] : #"NO_EMAIL";
But i need the real mail, so i have to come up with a new solution.
I haven't noticed something special with the problematic users.
Any ideas what can be the problem?
It appears that its a well known problem... For many reasons, not everyone on Facebook have Email address registered.
But as i said, my problem is that i need a real mail.
So the simplest solution is to use the user's Facebook Email : user_name#facebook.com
NSString *email = [user objectForKey:#"email"] ? [user objectForKey:#"email"] : [NSString stringWithFormat:#"%##facebook.com", user.username];
some links ref to that you can't sent HTML emails to the Facebook mail, only plain text!
Here is how i have done it and it always works great for me in every situation:
(I suppose that you have added email permission in your code)
Step 1
Open Facebook Framework folder in Xcode and find the FBGraphUser.h class
As you see, you have there all the properties that you use from Facebook Framework, to take the user details, so add an other property there (copy and paste the code below):
Step 2
#property (retain, nonatomic) id<FBGraphUser> email;
And you are good to go!
You could check for a couple of things:
Make sure you are requesting email scope permission in the login request dialog:
https://www.facebook.com/dialog/oauth?client_id=APP&redirect_uri=REDIRECT&state=UNIQUE&scope=email
Check if the access token you got actually has email permission granted with the Access Token Debugger.
All facebook accounts which are verified through Phone Number instead of email will get NULL for [user objectForKey:#"email"]
Facebook won't return the email address if it's not verified.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user
This person's primary email address listed on their profile. This field will not be returned if no valid email address is available.

Facebook request does not return email

No email is outputted from the Facebook request. How do I get this? I need it for my login/signup process
- (void)request:(FBRequest *)request didLoad:(id)result{
NSLog(#"FACEBOOK RESULT %# ", result);
}
This is the initial request:
[facebook requestWithGraphPath:#"me" andDelegate:self];
The email property cannot be obtained without requesting additional permission to obtain it, see https://developers.facebook.com/docs/reference/login/email-permissions/.
My application uses the following code to first check whether the Facebook session is valid (self.facebook is a Facebook object initialized with initWithAppId):
if (![self.facebook isSessionValid]) {
NSArray* permissions = [NSArray arrayWithObjects: #"email", nil];
[self.facebook authorize:permissions];
} else {
// Since we have a valid session we can get the userinfo
[self getFacebookUserInfo];
}
Your application prompt will indicate "Using this app requires: * Your basic info * Your e-mail address" If the user authorizes you to obtain this information your access token returned will have bits in set to allow you to obtain the e-mail address, and the following will work:
-(void)getFacebookUserInfo {
[self.facebook requestWithGraphPath:#"me" andDelegate:self];
}
assuming your -(void)request:(FBRequest *)request didLoad:(id)result method is available (which it appears that it is).
Note that the full flow of SSO (Single Sign On) is not given here in this post, you'll need to go through https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/#implementsso in detail.
Note also that you may be using a deprecated API for iOS 6, you should look at https://developers.facebook.com/docs/tutorial/iossdk/upgrading-from-2.0-to-3.1/ before going further.
With 2.4 api, parameters are used in order to specify which user data items you are interested in receiving.
E.g.:
FBSDKGraphRequestConnection *connection2 = [[FBSDKGraphRequestConnection alloc] init];
FBSDKGraphRequest *selfRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me?"
parameters:#{#"fields":#"id,name,first_name,last_name,verified,email"}];
[connection2 addRequest:selfRequest
completionHandler:^(FBSDKGraphRequestConnection *innerConnection, NSDictionary *result, NSError *error) {
if (error) {
NSLog(#"%#", error);
return;
}
if (result) {
// get user data
NSMutableDictionary *facebookUserData = [NSMutableDictionary dictionaryWithDictionary:result];
NSLog(#"result=%#", result);
HOWEVER, they apparently messed up big time, as email is NOT CURRENTLY being returned for DEVELOPERS, and currently in development Apps.
Incidentally, it is IMPOSSIBLE to submit bugs on Apps in development, as they require approved apps in the feedback system...
I wonder how do they think we are going to make sure that something works BEFORE submitting an app for approval, or what is the logic of asking for an App Store id of an App which can't be approved BEFORE Facebook integration can be tested to the fullest.
Besides, who is the genius at Facebook who decides to break working code one day from another?

Resources