iOS: Incorrect/Repetitive Facebook Request Message - iphone

I'm using the Facebook SDK and Parse.
I am submitting additional requests for the users email, events, and their friends' events.
Although I receive this info successfully, users who are logged into iOS' facebook system get this popup when I request permissions.
Notice that they are already logged into facebook (via the settings app) and they are simply getting a message to approve the request.
As you can see, it repeats the info about basic profile and friend list (FB login gives you this by default) and doesn't even mention the email. Since I doubt Apple or FB has made this kind of mistake, I assume it has something to do with me. Here is how I request access using FB and Parse.
// The permissions requested from the user
NSArray *permissionsArray = #[ #"email, user_events, friends_events"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[activityIndicator stopAnimating]; // Hide loading indicator
if (!user) {
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
}
} else if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
[self.delegate ViewWasDismissed];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
} else {
NSLog(#"User with facebook logged in!");
[self.delegate ViewWasDismissed];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
}];
again, this request WORKS. Therefore, I can't imagine what I could be doing wrong, but the message is strange. Any ideas?
EDIT: I tried deleting my account from the iOS facebook system and requesting directly through the app. This time I got this message:
Notice that here, the user is logged into facebook via the FB app and simply gets this (correct) message to accept permissions.
Is this some kindof bug with Apple's Facebook system?

This is the correct behaviour that will happened for iOS. Since iOS 6, Apple has integrated Facebook to the devices. Therefore, users can log in Facebook from Settings page. Below are the scenario that explain your confusions.
Scenario 1: Logged in to Facebook from Settings page
The app will automatically detect the Facebook account from your device if there's any, and prompt you the permissions request with UIAlertView. This only happen if you're using latest SDK and I am not so sure since which SDK that Facebook released for iOS has this.
Scenario 2: Not logged in to Facebook from Settings page (Old way)
The app will lead you to Facebook app if it's installed in your device. Else it will lead you to Safari with Facebook mobile page open and ask you for permissions that the app required.
Hope this help :)

Related

Trouble getting Facebook login and permission request will occur natively in iOS 6 and not fast-app-switch

I am having issues getting the permission request and login to happen natively in iOS, and am currently always getting the fast-app-switch where the authentication happens in a Safari window before switching back to iOS. I have ensured that I logged into Facebook using the Settings app in iPhone Simulator, as well as that I am only requesting read, and not both read and write permissions (in fact my permission array is empty, thus only getting a user's public profile and friend list).
I am using Parse API's PFFacebookUtils, which according to their documentation delegates to the Facebook SDK to authenticate the user.
Here is my code log in code:
- (IBAction)logInFacebook:(UIButton *)sender
{
NSArray *permissionsArray = #[];
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[self.activityIndicator stopAnimating];
if (!user){
if(!error){
NSLog(#"User cancelled the Facebook login.");
} else {
NSLog(#"Error occured: %#", error);
}
} else if (user.isNew){
NSLog(#"User with facebook just signed up and logged in.");
//Code to move to a new view. Not shown for breveity
} else {
NSLog(#"User with facebook already logged in.");
//Move to new view
}
}];
[self.activityIndicator startAnimating];
}
My question is - is my code causing the old fast-app-switch view to happen, or is some settings in iPhone simulator not done correctly? Thanks!!

Is it possible for user of an ios app to like a URL on facebook using the facebook-sdk?

I am creating an iOS app where I want to allow the user to like a specific URL. I've tried to use the following code (as mentioned on the Facebook developers page) to like a specific url:
**- (IBAction)likeClicked:(UIButton *)sender {
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[FBSession setActiveSession:appDelegate.session];
if (appDelegate.session.isOpen)
{
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"object"] = #"http://samples.ogp.me/226075010839791";
[FBRequestConnection startForPostWithGraphPath:#"me/og.likes"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Error %#",error.localizedDescription);
NSLog(#"result %#",result);
// handle the result
}];
}
}**
But the above code only allows me to like the URL if I am authorized as an admin of that app on the facebook developer page.
If I am not an admin to the app with that specific app id , I get an error description as following:
Error The operation couldn’t be completed. (com.facebook.sdk error` 5.)
There are different solutions given on Stack Overflow for this but none of them seem to be working for me. I've checked for permissions and I have added the "publish_actions" permission to permissions list.
Is there another reason why i might be getting this error?
Is there another workaround using which i can like a specific URL on facebook?
There would be couple of places to check
- Is your Facebook app under "sandbox mode", if it is you will have to turn it off once you are sure with your development.
If you have just created a FB graph action:
You are required to submit the action through the FB developer console and it usually takes couple days for them to approve, and once approved other users can start using the "like" action.
Until you get the action approved, only the App developers, testers and admins (on the FB developer site) for this particular app would be able to complete the action and see the results on their FB timeline.

Facebook iOS SDK Logout

I'm using the official and updated Facebook iOS SDK.
We're developing an application on an iPad that is used inside a physical store using an in-house distribution profile. Where customers can login to their Facebook account on an iPad that's publicly available to improve their shopping experience.
The problem I came across is that when a user logs into their Facebook account, the next user (customer) will still be logged in with the previous users' credentials (You have already authorized xxx, Press "Okay" to continue). Ofcourse this is not okay.
Is there a way to actually logout (sign off, clear credentials, or what ever) the previous (or current) user so the next user can fill in its own username and password.
Unfortunately [[FBSession activeSession] closeAndClearTokenInformation] doesn't quite do the trick.
This is a part of the code so far:
// ....
[[FBSession activeSession] closeAndClearTokenInformation];
[FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
// More code ...
}];
// ...
PS. The cookie 'workaround' doesn't work for me (obviously)
From your context, I'm assuming your device(s) does not have the Facebook app installed nor do you expect to use iOS 6 system authentication which would leave the default login behavior to use Safari. If you were to clear the Safari cookies, that should work but for a smoother experience in your scenario you should use the FBSession openWithBehavior:completionHandler: method and specify a behavior of FBSessionLoginBehaviorForcingWebview so that it uses the inline webview dialog for authentication.
See the SwitchUserSample in the Facebook iOS SDK for an example since that sample demonstrates an app that can toggle between multiple accounts.
Try with this code. I think it will help you.
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
If you are using facebook sdk 4.1.0 just call bellow method
if ([FBSDKAccessToken currentAccessToken]) {
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
}

iOS 6 - Facebook sharing procedure fails with error "The proxied app is not already installed"

Though, there is such a question Facebook Error (7) iOS 6 it's already closed without any answer!
While obtaining an access to user's facebook account I've got an error:
error is: Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: The proxied app is not already installed." UserInfo=0xa260270 {NSLocalizedDescription=The Facebook server could not fulfill this access request: The proxied app is not already installed.}
I'm performing a request like this:
self.statusLabel.text = #"Waiting for authorization...";
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary * dict = #{ACFacebookAppIdKey : FB_APP_ID, ACFacebookAudienceKey : ACFacebookAudienceEveryone};
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
__block NSString * statusText = nil;
if (granted) {
statusText = #"Logged in";
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
NSLog(#"account is: %#", self.facebookAccount);
self.statusLabel.text = statusText;
[self postToFeed];
}
else {
self.statusLabel.text = #"Login failed";
NSLog(#"error is: %#", error);
}
}];
What does this error means?
I've solved this problem!
It was because I do not pass permissions array!
Though the ACAccountStore class states that this parameter is optional, it is not!
More over the application could launch and ask for basic permissions(as it is implied)!
So, you must always pass a permissions array.
Here's also a description of error codes returned by account store:
typedef enum ACErrorCode {
ACErrorUnknown = 1,
ACErrorAccountMissingRequiredProperty,
ACErrorAccountAuthenticationFailed,
ACErrorAccountTypeInvalid,
ACErrorAccountAlreadyExists,
ACErrorAccountNotFound,
ACErrorPermissionDenied,
ACErrorAccessInfoInvalid
} ACErrorCode;
(I've got ACErrorPermissionDenied here)
We had the same problem and after taking a closer look at the iOS facebook documentation ad
https://developers.facebook.com/docs/howtos/ios-6/
I noticed the following paragraph:
Note, to use iOS 6 native auth, apps need change the way they request permissions from users - apps must separate their requests for read and write permissions.
I must have read over that one several time but it contained the solution:
You have to do multiple request for access if you want to grant write (publish access). So now we first ask for permission 'email' to get read permission and then for 'publish_action' to be able to post to the timeline.
The error message is not clear since "app" could be your iOS app? Facebook.app on the phone? Facebook app? The "proxied app" is the Facebook app, and "not already installed" means, it's not yet been associated with the Facebook user online in terms of permissions.
The first time your Facebook app connects to the users Facebook account, you must specify the basic info value(s) in your ACFacebookPermissionsKey key of the options dictionary. Other Facebook SDK's past and present such as the Javascript or PHP libraries by default supply basic info as the key, so you never had to. It seems the native integration in iOS doesn't do this, thus, if when the user first connects your app to their Facebook account with no permissions supplied, you get this error.
After you are given access, i.e. - after the user is connected to the app in their privacy settings online, ACFacebookPermissionsKey does as Apple document, become optional.
It's all a little confusing when you start to try and use the native Facebook integration...
Using the native Facebook integration you must provide one of the following keys which are basic info keys: email, user_birthday, or user_location.
To quote Facebook (source):
To create this basic connection using the iOS 6 native Auth Dialog,
apps must request access to a user's basic profile information by
asking for one of email, user_birthday, or user_location permissions.
After experiencing this error on one of my devices (after seeing the correct, expected iOS alert view asking for me to approve Facebook access to my app):
'The Facebook server could not fulfill this access request: Invalid application ID.'
I finally found the problem.
Although it initially appears to be a problem with the Facebook app setup on the FB developer site it turned out that my device's iOS Facebook account no longer had a valid password associated with it - this can happy when users restore an iOS backup to a new device. Once I sorted that in my device settings everything worked as expected.
I've not experienced any problems requesting 'publish_stream' in the first FB permissions access request - I actually think the real problem here is that the error messages are so random that they don't help developers to locate the source of the errors we're experiencing thanks to Apple and Facebook's lack of unity!
A few more things that one can try other than the above suggestions is checking your app settings on facebook.com here -
https://developers.facebook.com/apps/<*APP_ID*>/summary
Make sure that the SandBox Mode is set to Off
Also,
Under "Select how your app integrates with Facebook"
Select-> Native iOS App
Set your Bundle ID
You can set any temporary integer value for iPhone/iPad App store ID
Set Facebook login to Enabled
Listed Platforms is Native iPhone App &/or Native iPad App
Save changes and try after some time as it might take a few minutes for facebook to sync the changes to all its servers.

facebook-ios-sdk logout question

I have seen a lot of questions here regarding the Facebook Graph API but I still haven't find a solution for simple 'login'/'logout' operations using it. Looks like the Single Sign-On style is causing more confusion than benefits.
I'd like to know if it is possible have the following situation:
Enter in the app (no accessToken/expirationDate created).
Perform a login using SSO by calling authorize:delegate: method (application goes background and the login is made in the 'global' scope (Facebook App/Mobile Safari), asking for the user credentials.
Enter back in the app (now logged in, both accessToken and expirationDate are saved to NSUserDefaults).
Perform a logout by calling the logout: method (now logged out, both accessToken and expirationDate are removed from NSUserDefaults)
Attempt to perform a login again, with exactly the same steps done in 2.
I realize that when I call logout:, I do really log out from Facebook (accessToken is invalidated) from my App scope, not from the global scope (Facebook App/Mobile Safari). In 5.) when I try to log in again, the application goes to background and the login attempt is made again in Facebook App/Mobile Safari as usual, however I'm getting a screen saying that I'm already logged in:
You have already authorized .... Press "Okay" to continue.
Logged in as ... (Not You?).
It's a strange behavior for the user that has just logged out in my App.
My question is:
"Can I really log out from facebook (I mean 'global' scope) from inside my App? This would affect other apps using the facebook credentials too. However, if I can't to do this, how can I avoid the 'strange behavior' describe above?
Thanks
Eduardo,
I feel your pain! I spent the better part of a day working on this issue. I have discovered that when you use SSO and the call:
Called from your code:
[facebook logout:self];
Facebook API method:
- (void)logout:(id<FBSessionDelegate>)delegate {
self.sessionDelegate = delegate;
[_accessToken release];
_accessToken = nil;
[_expirationDate release];
_expirationDate = nil;
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
if ([self.sessionDelegate respondsToSelector:#selector(fbDidLogout)]) {
[_sessionDelegate fbDidLogout];
}
}
The facebook API does invalidate the access token and expirationdate variables and attempts to delete the mobile Safari cookies, but for some reason, probably Apple's fault the cookies are not really deleted. So when you attempt to login in the next time your mobile Safari will see the cookie and it says:
"You have already authorized .... Press "Okay" to continue. Logged in as ... (Not You?)."
Until either Facebook finds a fix or Apple fixes their broken API we must bypass SSO through Safari. Below are the changes I made to Facebook.m in order to force the old login dialog. If you used these changes they may not work forever but it is my guess that they will work for a very long time. Also to be sure this worked with the most recent facebook API I updated to the latest as of this post (Nov 2011 build).
Called from your code:
[facebook authorize:permissions];
Facebook API method:
- (void)authorize:(NSArray *)permissions {
self.permissions = permissions;
// [self authorizeWithFBAppAuth:YES safariAuth:YES];
[self authorizeWithFBAppAuth:NO safariAuth:NO];
}
If this helps you please up rate this thread and my post to help others find it.
gadildafissh
I'm afraid the answer is no, you can't do this.
Your application is in a sandbox, and can't write outside, where global cookies are (for mobile safari) and Facebook app settings (in Facebook app preferences/cookies I think)
You can only warn your user to logout outside of your app...
...Or you can just not use facebook api SSO, but in app login webform, like I do for other reasons.
If you choose that option this pull request might save you some time ;)
Hii ,
its not possible , the reason is for Single Sign On (SSO) is not to make user login everytime, he logouts , instead if the user logs in anyone of FB enabled apps - it will use that to login again - This is because the device is mostly used by single person in this case only one user can login in Facebook.
you can't control any app outside of your app - for Example - if u login with Gmail & when you open google.com you can see your username there is currently logged In which has SSO,
In new SDK of Facebook, you can set login button loginBehaviour property
Below code in swift ...
let fbButton = FBSDKLoginButton()
fbButton.loginBehavior = .Web
Answer already done, but I just want to clarify it. May be it saved somebody's time.
Go to Facebook.m and change line
[self authorizeWithFBAppAuth:YES safariAuth:YES];
to
[self authorizeWithFBAppAuth:YES safariAuth:NO];
It will cause login window appear inside the app. Logout will work perfect. In other words, it will work as it used to in older versions of OS.
in addition to kishnan94 answer. the objective c version is ;
if you want a modal to open up and ask for facebook credentials seperately from Safari or Facebook app, just use the latest facebook sdk and set the login behaviour
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login setLoginBehavior:FBSDKLoginBehaviorWeb];
this will make the logout process more convenient and less confusing for users without using safari or facebook app accounts.
It seems that this is a bug of Facebook SDK. In a case of the Facebook app is installed on device, access_token is renewed. In other hand, access_token and expirationDate could not be changed. :((