Currently I am using FBSDKLoginManager with a Facebook app id to sign in via Facebook into my application. I have the required things in .plist file. Everything works fine.
But now I have to login in another section of my application with a different Facebook app id. How could I use different Facebook app id in a single application in various area.
Someone already asked this question previously. From the answer I found
FBSession *session = [[FBSession alloc] initWithAppID:#"AN_APP_ID"
permissions:nil
defaultAudience:FBSessionDefaultAudienceNone
urlSchemeSuffix:nil
tokenCacheStrategy:nil];
[session openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
// do stuff here
}];
But the answer does not work for me as FBSessionis not available. Any idea? Suggestion?
Refer to this tutorial that specifically addresses your problem in particular, and how to manage different environments in general: https://medium.com/slalom-engineering/ios-managing-multiple-environments-with-a-single-target-94cf823a6447
To go directly into what you want, search for "FacebookAppID" on that link.
Related
I need some help on this one ....
So the problem I am facing is that while fetching the Facebook account from ACAccount, the alert view informs too many permissions. I am getting an alert box when I use the ACAccount login for facebook.
It says APP_NAME would like to access your basic profile info and list of friends
This shows up even when my permissions set is an empty array.
NSArray * FB_PERMISSIONS = #[];
// or FB_PERMISSIONS = #[#"public_profile", #"likes", #"email"];
// It does not matter what the array is -> The alert has extra sentences.
ACAccountType *FBaccountType= [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"FacebookAppID"];;
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,FB_PERMISSIONS,ACFacebookPermissionsKey, nil];
[_accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
What am I trying to do here?
I am just needing the "public_profile", #"email" and "likes". The alert says APP_NAME would like to access your profile, and likes on your behalf. In addition, APP_NAME would like to access your basic profile info and list of friends
Why is that second sentence there? How do I get rid of it? I can see a number of apps where the second line that talks about basic profile and list of friends does not show up.
Expected result:
APP_NAME would like to access your profile and likes.
Update:
Check my answer for solution.
There is nothing in the FB SDK docs that explain any of this. They made this way so that users can use the Facebook pop UI and pick the permissions they want to authorize. I guess Facebook design's philosophy is to give as much control and transparency to the user. But with the OS pop-up it hides a lot of permissions underneath. I guess it's Apple's design philosophy to show minimal information. This works best for developers scenario, as users usually freak out when they see so many permissions being asked by the app.
Anyway, if you take a look at FBSDKLoginManager+Internal.h you can checkout the capabilities for System login. Further digging, I've discovered that FBSDKLoginButton is pointless. The best way to go about this is using your own instance of FBSDKLoginManager, and set the system account type to be native, and if you get the error code 306, fall back to default login mechanism.
Somehow ->> This way does not show additional permissions. I have no idea how. All I know is that everything falls into place now.
Further more, you will have to setup a separate listener for ACAccountStoreDidChangeNotification so that you can tie up some edge cases. But yes, \m/
The Fix
The fix to this problem involves adding code to the view header file as well as adding code to your view file. The code examples are listed below.
To the view header file add:
// ViewController.h
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;
#end
And to the view file add:
loginButton.readPermissions =
#[#"public_profile", #"email", #"likes"];
Note that the comment in the first example was just for reference.
Why did it happen?
The reason why your problem happened was because the Account Framework and Facebook API think by default that you mean every permission there is. It requires you to be more specific in the code. I am pretty sure that you for got to do the first example of code which was supposed to go in your view header file. I understand that the code above is not what you will put in the file you are working on, but it just gives you a rough idea on doing it.
Still Confused?
If you are still confused please comment below and I will try to update my answer. It would be really helpful if you could send the code you were doing with he arrays filled not blank. If I wasn't clear please tell me and I will do the best I can to help. Sorry if there is any inconvenience!
Sources
Mainly, I found the info on here: https://developers.facebook.com/docs/facebook-login/permissions/overview and over here: https://developers.facebook.com/docs/facebook-login/ios#permissions
Facebook is pretty trustworthy and creditable. I think...
Is there a reason you're not using the Facebook API instead? Requesting access via iOS APIs will require the user to be logged into Facebook via the iOS Settings. If you make the same request with Facebook's API, it can detect if the user is logged in via the settings, the FB app, or Safari. And if the user is not logged in, it'll prompt them to do so (as opposed to just erroring out and telling them to do so via settings)
Version 4.X:
https://developers.facebook.com/docs/facebook-login/ios/permissions
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:#[#"public_profile", #"likes", #"email"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//TODO: process error or result
}];
Version 3.X
[FBSession openActiveSessionWithReadPermissions: #[#"public_profile", #"likes", #"email"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
// Handle completion by calling AppDelegate
}];
I'm trying to log into facebook with their API using
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}]
The problem I'm having is in iOS 6.x when the device has a facebook account linked in the settings app it fails to log in. The error it gives is the seemingly one-size-fits-all error 2. This is the only case where it fails and I can't understand why. What is a solution to let me log in while an account is linked?
check that your permissions array does not contain the offline_access permission. this permission is now deprecated and has been known to cause login to fail. i previously searched stack overflow and found this answer. you'll also need to go into Settings -> Facebook and switch the permission on the Allowed Apps to On.
I was getting this error due to the app being sandboxed. Check facebook developer and add your team.
Go to settings. Scroll all the way down until you see Facebook on left hand side
tab, on it, allow these apps to use your account (right hand side).
Look for the app that gives you the sdk error 2.
My app uses Facebook SDK 3.0. I don't have a Facebook account in iOS settings but I have an installed Facebook app on a device (iOS 6.1.3) and want to login to Facebook in my app. I call:
NSArray* aPermissions = [NSArray arrayWithObjects: #"user_about_me", #"user_activities", #"user_interests", #"user_notes" , #"read_stream", #"user_status", #"user_likes" , #"friends_likes", #"user_hometown", #"user_location", #"email", nil];
FBSession* session = [[FBSession alloc] initWithAppID:FACEBOOK_API_KEY
permissions:aPermissions
defaultAudience:FBSessionDefaultAudienceEveryone
urlSchemeSuffix:nil
tokenCacheStrategy:nil];
[session openWithBehavior: FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self connectResult:error withState:state];
}];
And my app opens Facebook app and then it returns me back to my app. It's great, I like how it works.
But I found that Facebook has new SDK 3.5.1 and I decided to update my old SDK. And when I did it I found that this SDK doesn't open a Facebook app, it just presents a dirty WebView above a current view. This is terrible because user should remember his login and password. What can be wrong in my case? Did I miss something? Does Facebook disabled login through a Facebook app?
The code in these two cases are same.
It's from the fast app switching URLs thing. You probably have a fb$(FB_APP_ID) like url but it's declared as a second while the FB SDK looks only at the first resource:
https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBUtility.m#L381
This won't work
This will work
I am using following code to access the facebook
[FBSession openActiveSessionWithAllowLoginUI:TRUE];
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"email",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (error) {
NSLog(#"Failure");
}
else
{
}];
It is working fine when user has enabled the facebook account in iOS setting and also when there is no account enabled in iOS settings then it goes to safari for facebook authentication. But suppose user has first enabled the account with abcd#gmail.com and then after some time he has added new account i.e. efgh#gmail.com. So how the app come to know that user has changed his/her account in iOS settings. How to check it by using facebook SDK. Anyone has idea?
Thanks to all.
The information (access token, etc) stored inside a FBSession is entirely independent of any other account authority (this includes iOS6, Safari, or the Facebook app). Those other authorities are only used to connect your app, once it's connected, your app operates independently. This means that even if the user logs out, and logs in again with a different id, it doesn't affect your app at all. The user of your app needs to proactively log out inside your app, and initiate another login in order to change accounts.
This is why it's vitally important that the user has a way of identifying themselves inside of your app (either through a profile picture, and/or their name displayed somewhere), so they know which account they're using.
I downloaded the new Facebook iOS SDK 3.1, which promises to have a native login prompt. I ran their sample login app on my iOS 6 device. When I attempted to connect with Facebook, I did not get a native login. Instead, the Facebook app launched - same as the old SDK. Their Facebook login button basically does this:
[appDelegate.session
openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self updateView];
}
];
I thought maybe the sample code isn't calling the right function. So I tried FBSession's other login function.
[appDelegate.session
openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self updateView];
}
];
I tried all possible behaviours and none of them popped up the native login prompt.
Did you log into Facebook from the iOS settings first?
Once you do that, their example project Scrumptious will use the native login prompt when you try to connect.
Read this: https://developers.facebook.com/docs/howtos/ios-6/#nativeauthdialog
Basically you must request basic permissions and read permissions first and then request publish permissions separately.
This is by design, and described in the second section of https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/upgrading-from-3.0/
Basically, you are not able to ask for both read and publish permissions with the iOS6 dialog. Therefore you are more-or-less required to ask for them in a staggered way (e.g. read on first login, and then publish when your app actually needs to publish).
If you insist on using the deprecated method to try and get read & publish at the same time, the SDK has no choice but to return to the web or app-switched technique.