Publish Feed - Facebook SDK 4.0 - ios

I have integrated by iOS APP FBSDK 4.0. I have used
FBSDKLoginManager *login = [[FBSDKLoginManager alloc]init];
[login logInWithReadPermissions:#[#"public_profile",#"email",#"basic_info"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error)
{
[[AlertView sharedAlert] showAlertWithTitle:kAlertError Message:#"Login Error.Try after sometme" CancelButton:kAlertOKButtonTitle OtherButtons:nil];
}
else if (result.isCancelled)
{
NSLog(#"Login Cancelled");
}
else
{
NSLog(#"%#",result.grantedPermissions);
[self handleFBLoginResult];
}
}];
to login using FB and this step generates an access token which doesn't have publish permissions.
Then in other part of the app, when the user taps on publish to FB action, I am calling below method
FBSDKLoginManager *login = [[FBSDKLoginManager alloc]init];
[login logInWithPublishPermissions:#[#"publish_actions"] fromViewController:topController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if ([[result declinedPermissions] containsObject:#"publish_actions"])
{
[[AlertView sharedAlert] showAlertWithTitle:kAlertWarning Message:#"Publish Permission Denied.Please check your FB profile settings" CancelButton:kAlertOKButtonTitle OtherButtons:nil];
}
Please see attached screenshot.
declined permissions is set to nil
granted permissions is set to nil
user cancellation action is set to YES , whereas I haven't cancelled anything
Looks like my permissions are not getting set and I am not able to post any feeds
[[[FBSDKGraphRequest alloc]initWithGraphPath:#"/me/feed" parameters:postDict HTTPMethod:#"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"%#",[[FBSDKAccessToken currentAccessToken] tokenString]);
if(error == nil)
{
NSLog(#"Checkin Posted");
}
else
{
//NSString *errMessage = [[[[[error userInfo] objectForKey:#"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:#"body"] objectForKey:#"error"] objectForKey:#"message"];
NSString *errMessage = [error localizedDescription];
[[AlertView sharedAlert] showAlertWithTitle:kAlertError Message:errMessage CancelButton:kAlertOKButtonTitle OtherButtons:nil];
}
}];
This code above is failing to post the feed in FB and throws error message
Facebook error: (#200) The user hasn't authorized the application to perform this action.
I am gone through some solutions mentioned but it didn't help me.
Any suggestions would be helpful.

Related

Why iOS Facebook Signup Email id not returned in my account?

I'm using signup with Facebook. Other Facebook login works fine. Some accounts are working fine, but some accounts are not returning email. If anyone knows the reason please help me!
- (void)facebookOpenSession{
NSArray *permissions = [[NSArray alloc] initWithObjects:#"user_birthday",#"basic_info",#"user_location",#"user_likes",#"email",#"public_profile",#"user_hometown",#"user_about_me",nil];
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: permissions
fromViewController:self.view.window.rootViewController
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {
} else if (result.isCancelled) {
} else {
if ([result.grantedPermissions containsObject:#"email"])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me"
parameters:#{#"fields": #"picture, email,name,first_name,last_name"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
if ([result objectForKey:#"email"]!=NULL)
{
[self newFbLoginFunction:result];
}
}
}];
}
}
}];}
Response like this:
{
"first_name" = AAAA;
id = 1XXXXXXXXX2258;
"last_name" = BBBBB;
name = "AAAA BBBBB";
picture = {
data = {
"is_silhouette" = 0;
url = "https://fb-s-c-a.akamaihd.net/h-ak-xpa1/v/t1.0-1/p50x50/XXXXXXXXXXX3212_3395344935279367518_n.jpg?oh=7345e4de6XXXXXXXXXXXX8&oe=58E16A60&__gda__=14951668XXXXXXXXXX2bc0aec58eab3f25e47";
};
};}
Not all users use an email to login, you can also use a phone number. Also, emails need to be approved by Facebook or they will not show up with the API.
In other words: You can never guarantee to get an email back. Present an email input field to the user if you canĀ“t get the email with the API.

How to get the emaiil id from facebook if i login with phone number in ios?

I am integrating the facebook integration in the iOS application for login in my application.
Is it possible to get the email id from the facebook API in iOS if we login through the facebook by using phone number.
Currently i am using the following code.
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:#[#"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
} else if (result.isCancelled) {
// Handle cancellations
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:#"email"]) {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"fetched user:%#", result);
}
}];
}
}
}
}];
You will get email address if user has signed up with email. In case of user has signed up with phone number you may get email field as empty. Please have a look at Facebook developers reference.
https://developers.facebook.com/docs/facebook-login/permissions#reference-email
Note, even if you request the email permission it is not guaranteed you will get an email address. For example, if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty.

Getting Error 307 when trying to login with Facebook using Parse PFFacebookUtils

I'm trying to log in with Facebook using Parse.com's PFFacebookUtilsV4. I'm using their standard:
PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile"])
{ (user, error) in
When I have connected my FB account to my iPhone in my iPhone's settings. I get an error with code 307 (shown below) every time. If I delete the FB/iPhone account connection from my iPhone's settings, the error goes away and the standard authentication happens. I'm testing on my phone. I have the FB app on my phone, but that doesn't seem to affect the error. Just having it connected via my iPhone's settings.
After digging deeper into the stack trace, I found a different error. This solved it iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id"
Just in case anyone has any other errors with login with Facebook on parse here's what I learnt
Add this key to your parse server dashboard FACEBOOK_APP_ID (near where you add MASTER_KEY)
You will have to switch up from the following method
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
to first executing the standard Facebook get token
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: #[#"public_profile"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in");
NSString *facebookUserId = [FBSDKAccessToken currentAccessToken].userID;
NSString *accessToken = [FBSDKAccessToken currentAccessToken].tokenString;
NSDate *expirationDate = [FBSDKAccessToken currentAccessToken].expirationDate;
[self loginFacebookUserWithTokenInfo:facebookUserId
accessToken:accessToken
expirationDate:expirationDate];
}
}];
Then you login using the following section of code
[PFFacebookUtils logInWithFacebookId:facebookId
accessToken:accessToken
expirationDate:expirationDate
block:^(PFUser *user, NSError *error) {
if (error) {
NSLog(#"Error!");
} else {
NSLog(#"User logged in through Facebook and parse!");
// do as you please
}
}];

FBSDKLoginManager works, PFFacebookUtils logInInBackgroundWithReadPermissions not

I implemented the login via Facebook with parse server.
If I use this, I get user information correctly:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: #[#"public_profile",#"email"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in %#",result);
[self fetchUserInfo];
}
}];
but I want to use PFFacebookUtils for easy user creation in Parse:
[PFFacebookUtils logInInBackgroundWithReadPermissions:#[#"public_profile",#"email"] block:^(PFUser *user, NSError *error) {
if (!user) {
//...
} else if (user.isNew) {
//...
} else {
//...
}
}];
The Facebook modal appears with the authorization request, but when I press ok, I get this error:
[Error]: Facebook auth is invalid for this user. (Code: 101, Version: 1.13.0).
Inside the applications settings on Facebook, the app there.
It occurs in Parse app when the user changed Facebook password or removed your app in the applications settings on Facebook.
User.authData should be updated with PFFacebookUtils.logInInBackgroundWithReadPermissions:, but it seems to be not updated. I think that this is problem of Parse Server.
Workaround: When that error occurred, you can update User.authData with PFFacebookUtils.linkUserInBackground:withReadPermissions:.

FB Connect wont work on certain devices

So here's a weird one, in one of my apps i have this FB login code:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:#[#"public_profile", #"user_friends ", #"user_likes", #"email", #"user_birthday"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
NSLog(#"error in opening facebook session - %#", error.localizedDescription);
handler(NO, nil, error);
}else if (result.isCancelled){
// Handle cancellations
handler(NO, nil, error);
}else{
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
FBSDKAccessToken *token = [FBSDKAccessToken currentAccessToken];
handler(YES, token.tokenString, nil);
}
}];
Some of my Beta users have been complaining that the app crashes once they click on the FB login button. I have check my Analytics services and i can see that it is ture.
Now the problem arises here, i have logged in (with my device) into one of my Beta testers FB account to debug this, but for some reason the FB connect works good.
Does any one have any advice or this may have happened to someone?
Thanks

Resources