Facebook request does not return email - ios

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?

Related

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)

Getting the user’s Facebook list of friends

After being able to create a small iOS app that logs in to Facebook. I would like this app to get the user’s list of friends.
Though I browsed the internet for a while and tried various approach I did not succeed to get what I wanted.
In the viewDidLoad method I use this code to start with:
loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"user_friends"]];
And then I implement the loginViewFetchedUserInfo: user: method this way:
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#“Result: %#",result);
}];
}
When I execute the app I get this result:
Result: {
data = (
);
summary = {
"total_count" = 267;
}; }
But what I really want is a list of the friends with their names …etc…
All the things I tried for that didn’t work. Though I suppose the solution must be simple.
I also used code like this in the method above ….. but with no luck:
NSArray* friends = [result objectForKey:#"data"];
One more point, here https://developers.facebook.com/docs/graph-api/reference/v2.1/user/friends one can read:
This will only return any friends who have used (via Facebook Login)
the app making the request.
But the result I get (267) does not match this statement. It (267) is the number of friends the user has on Facebook, which is in fact what I am interested in.
I hope someone has something to say to put me on the right track and make things clearer.
Since Facebook's 2.x SDK upgrade they have tightened up access to information in the "Open Graph API."
Under Permissions That Do Not Require Review
App friends. This optional permission grants your app the ability to read a list of friends who also use your app.
You get automatic access to any friends that already use your app (per its Facebook ID.)
You will have to request Extended Permissions if you want to access the list of all a user's friends. That means going through Facebook's App Review process which can be quite challenging (and annoying.)
Frankly, I am not even sure that it is possible to use the new Open Graph API to get the user's entire friend list.

FB Graph API - Create event on behalf of page -> error 403

I have been trying to create an event on the behalf of my page using the Facebook Graph API for iOS.
However, I always fail with the error code 403. I have tried to create an event on behalf of me - and surprisingly that works. The permissions are set appropriately as stated here.
My code goes like:
NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"Test",#"name",
#"2012-11-11", #"start_time", nil];
[FBRequestConnection
startWithGraphPath:#"12345/events"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", result);
} else {
NSLog(#"Success: %#", result);
}
}];
How I said, if I set the ID/events to my user ID instead of my Page's ID, it works. Could I have set up something badly on my page? Do I need admin rights for that page?
I found something about access tokens to "Perform the following operations as a Page" here. Do I need that? If so, how do I do it?
Thanks to everyone in advance!
To authenticate as a Page (and from there, edit the events) see this document: https://developers.facebook.com/docs/authentication/pages/
In short, authenticate as user who is an an admin of the Page. Then:
https://graph.facebook.com/me/accounts?access_token=xxx
in order to retrieve the access token for the Page (and indeed for any other Pages the user administers).
Then use that access token to administer the events for the Page.

ios-Facebook SDK 3.0 Error 5 When Posting Status Update

I am trying out adding facebook integration in an app using the new (beta) facebook ios sdk 3.0. All I would like to is post a status update to facebook. I used a FBLoginView to login to facebook. I put my app id in the plist as instructed on facebook. I put in some code to post to facebook.
(void)viewDidLoad
{
[super viewDidLoad];
NSArray *perms;
perms = [NSArray arrayWithObjects:#"status_update", nil];
FBLoginView *loginview =
[[FBLoginView alloc] initWithPermissions:perms];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)poststatus:(UIButton *)sender {
NSString *message = [NSString stringWithFormat:#"Test staus update"];
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:message result:result error:error];
}];
}
- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error {
NSString *alertMsg;
NSString *alertTitle;
if (error) {
alertMsg = error.localizedDescription;
alertTitle = #"Error";
} else {
NSDictionary *resultDict = (NSDictionary *)result;
alertMsg = [NSString stringWithFormat:#"Successfully posted '%#'.\nPost ID: %#",
message, [resultDict valueForKey:#"id"]];
alertTitle = #"Success";
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
The odd thing is, this code works ONCE. After authenticating the user for the first time, I can post ONE status update successfully. After that, all subsequent attempts will fail with a FBiOSSDK error 5 (in the console, Error: HTTP status code:400). The only way to fix this is to remove the app from the facebook account and re-authenticate. I'm not sure what the problem is. I looked online for solutions but couldn't find anything. If anyone knows how to fix this, please let me know. Thanks
com.facebook.sdk error 5 is always irritating while working with Facebook iOS sdk. Most of the times it comes with addional in console Error: HTTP status code:400. Its a perception that there is a bug in Facebook iOS sdk that produces this error randomly. I think this error occurs for some certain reasons and sdk do not provide actual reason of error when it occurs.
Several Possible Reasons
Every request in sdk is accomplished with completion blocks that we actually pass as argument in completionHandler. This error occurs when a block is in progress and made another request. A simple example might be If you have written request to post on Facebook (startForPostStatusUpdate::) on some button action. On single button tap it would work fine but if you double tap on button it will throw this error com.facebook.sdk error 5
If you are trying to post when your current session is not opened. e.g. Once sign in with Facebook then kill the app then reopen and then try to share on Facebook, Result -> com.facebook.sdk error 5. In this case try to reopen session using
Facebook do not allow same status to be posted repeatedly, they think it might be some kind of spam e.g. If you are trying to update status and you have hard coded a string lets say #”This is a test status update” you are posing again and again. After 5 to 10 attempts they wont allow you to do anymore. Resulting com.facebook.sdk error 5. If this is the scenario you should change your status string and try updating.
Facebook has defined a limit for a particular user to post status using sdk. e.g If you are trying to update status and you have done lets say 15 to 20 status updates. They wont let you do more Resulting -> com.facebook.sdk error 5. In this scenario try to unauthorize the app from your Facebook account and reauthorize it OR try using other Facebook account
It seems there might be no answer to the issue. I have checked FB samples coming with SDK, in these examples also the same error happens. So it means after few status updates (15-20) Facebook reaches limits for that particular user. If you log-out for that user and log-in as another user, you can successfully post.
If I will find any extension to limit settings I will reply.
Also Facebook doesn't allow for the same Post.
Use a proxy !
FB ios SDK is just a wrap to an HTTP request to graph.facebook.com/....?access_token=.....
So you can easily replicate the request or use an HTTP proxy to see the real server answer (which is not error 5 !).

Can't get user info from Facebook with OAuth 2.0

As soon as the user is logged in, I retrieve the user info using this code:
[_facebook requestWithGraphPath:#"me" andDelegate:self];
It worked for the first few times, but it eventually returned an error. I thought it was a session thing since I have "offline_access" on my permissions. I logged out from Facebook and compiled again from a clean build and it still returns this error:
Error Domain=facebookErrDomain Code=10000 UserInfo=0x54a2930 "Operation could not be completed. (facebookErrDomain error 10000.)"
I'm assuming my access token is valid since I can do posting. Am I right to assume that?
I also noticed that whenever I log in, Facebook doesn't redirect me to ask permission if I allow my app to access my user info.
Can anyone tell me what's wrong?
Answer on authorize command seems to be different. Now, there's no expiration date as it was before. I tried with forcing isSessionValid to return TRUE, and it works.
isSessionValid checks accessToken AND expirationDate. As there's no expiration date, the function return FALSE.
Don't know if it's a temporary modification from facebook, or definitive one. In this case, SDK must be fixed, I presume. And a new call must retrieve expirationDate.
Here's a temporary fix I've used. You can find this method line 46 in FBLoginDialog.m
- (void) dialogDidSucceed:(NSURL*)url {
NSString *q = [url absoluteString];
NSString *token = [self getStringFromUrl:q needle:#"access_token="];
NSDate *expirationDate = [NSDate distantFuture];
if ((token == (NSString *) [NSNull null]) || (token.length ==0)) {
[self dialogDidCancel:url];
[self dismissWithSuccess:NO animated:YES];
} else {
if ([_loginDelegate respondsToSelector:#selector(fbDialogLogin:expirationDate:)]) {
[_loginDelegate fbDialogLogin:token expirationDate:expirationDate];
}
[self dismissWithSuccess:YES animated:YES];
}
}
Does everyone with this issue request the offline_access permission? It's the only reason I can see an expiration date not being sent. Maybe try not requestion the offline_access permission.
I've had same problem. I checked my privacy settings,permissions,other method etc..., but I couldn't solve it.
Many sites said "check permission for accessing to offline_access/read_stream/publish_stream",I think these are important too,but I couldn't fix it.
Then I found following solution finally, it works fine.
You should change "safariAuth:YES" to "safariAuth:NO" on "Facebook.m" file.
- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate {
[_permissions release];
_permissions = [permissions retain];
_sessionDelegate = delegate;
//[self authorizeWithFBAppAuth:YES safariAuth:YES];
//You can get auth_token in iOS App!
[self authorizeWithFBAppAuth:YES safariAuth:NO];
}
Then you can use following method to get your own info if you are logged in.
[facebook requestWithGraphPath:#"me" andDelegate:self];
if you are not logged in, You should login by following method first.
permissions = [[NSArray arrayWithObjects:
#"email", #"read_stream", #"user_birthday",
#"user_about_me", #"publish_stream", #"offline_access", nil] retain];
if (![facebook isSessionValid]) {
[facebook authorize:permissions delegate:self];
}
Following post saved me.Thank you so much!
How to retrieve Facebook response using Facebook iOS SDK
Good Luck & Happy-coding!
Thank you.
I've had this problem, mainly because my Facebook account has is maxed on privacy.
It's most likely the permissions that you passed in during login. BY default it will only give access to public info. Remember there is less and less info that is public in Facebook.
Try changing your permission to something like "read_stream",nil
Then instead of [_facebook requestWithGraphPath:#"me" andDelegate:self];
Try using [_facebook requestWithGraphPath:#"me/home" andDelegate:self];
This should return your news feed.
Worked for me 5 mins ago.
Not much to add here, doesn't work here too. I use the iOS SDK to post to the stream and it worked until yesterday. Today my client called me and complained. Ugh.
I have requested the offline access permission and of course the "publish_stream" permission...

Resources